Solved

crontab

Posted on 1998-06-25
22
388 Views
Last Modified: 2010-03-04
I want to run a perl script twice a day at 11:55 am and 11:55 pm. My system administrator does not have crontab installed or does not want to take the time to learn how to use it. I have my own domain and I have a cgi bin. How can I get this script to run automatically twice a day?
0
Comment
Question by:timshank
  • 8
  • 6
  • 4
  • +2
22 Comments
 
LVL 51

Accepted Solution

by:
ahoffmann earned 100 total points
ID: 1208195
while (1) { system("you script"); sleep 43200; }

start at 11:55

(not very nice, but simulates a cron;)
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1208196
Change providers! :)
0
 

Author Comment

by:timshank
ID: 1208197
I'm not sure what to do with that information you just gave me, could you elaborate for me a bit please? I can configure a perl script w/ some work, but I am just learning the language
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1208198
Write the first line of my first comment in a script (replacing "your script" with the appropriate path to the script you want to run twice a day), then start this script at 11:55.
That's all. It simulates the cron mechanism.
0
 

Author Comment

by:timshank
ID: 1208199
I put the following script in my directory that contains the perl script

#!/usr/bin/perl

while (1) { system("/home/www/myurl/scripts/accesswatch/accesswatch.pl"); sleep 300; }

and named it cron.cgi. I used the 300 to test if it would access it every 5 minuites

when I ran cron.cgi it ran the perl script but hasn't ran it since, what did I do wrong?

0
 
LVL 84

Expert Comment

by:ozo
ID: 1208200
Is it still running?
0
 

Author Comment

by:timshank
ID: 1208201
how can I tell? is there a command I type in telnet to see if it is still running?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1208202
ps -ef   or   ps aux
0
 

Author Comment

by:timshank
ID: 1208203
Here is the message I get when I type in either command. I did discover that the script will run as long as I have a telnet session open, but as soon as I lose my telnet link it won't update the script anymore.

heras:/www/myurl/scripts/accesswatch$ ps -ef
warning: `-' deprecated; use `ps ef', not `ps -ef'
Error: /proc must be mounted
  To mount /proc at boot you need an /etc/fstab line like:
      /proc   /proc   proc    defaults
  In the meantime, mount /proc /proc -t proc
Error: /proc must be mounted
  To mount /proc at boot you need an /etc/fstab line like:
      /proc   /proc   proc    defaults
  In the meantime, mount /proc /proc -t proc
heras:/www/myurl/scripts/accesswatch$ /proc -t proc
bash: /proc: is a directory
heras:/www/myurl/scripts/accesswatch$ ps ef
Error: /proc must be mounted
  To mount /proc at boot you need an /etc/fstab line like:
      /proc   /proc   proc    defaults
  In the meantime, mount /proc /proc -t proc
Error: /proc must be mounted
  To mount /proc at boot you need an /etc/fstab line like:
      /proc   /proc   proc    defaults
  In the meantime, mount /proc /proc -t proc
heras:/www/myurl/scripts/accesswatch$      
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1208204
Uups, you've a somehow limited telnet access :(

try following:

heras:$ cron.cgi&
heras:$ jobs

`jobs' should report something like

[1]  + Running     cron.cgi
0
 

Author Comment

by:timshank
ID: 1208205
It seems to be running. I didn't restart it when I initiated the new telnet session. Thanks for your help by the way, I love learning new stuff.

heras:/www/myurl/scripts/accesswatch$ cron.cgi&
[1] 19537
heras:/www/myurl/scripts/accesswatch$ jobs
[1]+  Running                 cron.cgi &
heras:/www/myurl/scripts/accesswatch$    
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:timshank
ID: 1208206
The script is running but it still is not running my perl script, why would that be?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1208207
Sounds that you have a problem in your perl script.
Did you give a full path at perl's system() call?
You also may try following:

while (1) { system("/full/path/you_script >/tmp/log 2>&1"); sleep 43200; }
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1208208
Hmmmph. Logging's a very good idea, verifying that all is running is a good idea, but....

You've got a provider that won't let you do a cron job, because "My system administrator does not have crontab installed or does not want to take the time to learn how to use it."
[Ob Side note: Anyone who doesn't _know_ how crontab works _isn't_ an SA, and anyone who doesn't want to take the time to learn isn't _worthy_ of being an SA.] Furthermore, if there's no cron on your system, maintenance is either not being done, or is being half-done by hand.

:) I want the points for "Change Providers".  If you increase the points, I'll take them for "Fire the System Administrator, and hire a high school kid" :)

([ozo and ahoffman]) No disrespect to your valiant efforts intended....Honestly, though, it's abominable that a user should have to put up with this kind of .... sewage!

Cheers
0
 

Expert Comment

by:adrianward
ID: 1208209
A thought: Wont the script get killed as soon as the user logs off?

My knowledge in this area is weak and I dont have my documentation with me, but could you use nohup?

ie, when you come to run your cron-script, do it as
heras:/www/myurl/scripts/accesswatch$ nohup cron.cgi &

which will prevent it from receiving quit signals (sent by your shell when you log out)
0
 

Author Comment

by:timshank
ID: 1208210
the nohup worked, but unfortunatly I had it set to run every 5 minuites because I was testing it. Now the file keeps running every 5 minuites instead of every 12 hours. I even deleted the cron.cgi off of my site and it still keeps running, how can I stop it so I can restart it to run every 12 hours? Thanks
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1208211
> how can I stop it

   ps ax
or
   ps -ef
(depends on the OS) will give you the PID, the do a
   kill -TERM <PID>

If you hav no shell access to the system, you also may do it via perl.
0
 

Author Comment

by:timshank
ID: 1208212
It wont give me the pid, it keeps telling me that proc needs to be mounted. what are my other options?

(I'm about ready to take b2pi's advice on this one)
0
 
LVL 84

Expert Comment

by:ozo
ID: 1208213
How about renaming your
/home/www/myurl/scripts/accesswatch/accesswatch.pl
:-)
0
 
LVL 84

Expert Comment

by:ozo
ID: 1208214
Or how about replacing it with a program that looks at its ppid and kills it?
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1208215
It looks to me like he's on a proc FS system, and doesn't have read access to /proc.  Be willing to bet this is Linux, and you don't have an SA.

If that's the case, I think that any method you would use to get a pid or ppid would fail for the same reason.... Hmmm, except maybe ozo's last one.  That could work.

Honestly, I first proposed it as a joke.  You've been playing about with trivia for a month now.  People like this don't deserve to stay in business.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1208216
unfortunately, if you used
 system("/full/path/you_script >/tmp/log 2>&1")
then getppid would be the pid of the shell doing the redirection, instead of the program doing the system call...
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Perl Tutorial 6 127
perl search and replace 6 161
perl CPAN issue 3 90
Using Perl to parse rows 7 86
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now