Forum Moderators: coopster & phranque

Message Too Old, No Replies

Using Perl to invoke crontab

Can this be done???

         

volatilegx

1:29 am on Jan 19, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm writing a perl script that needs to use the crontab system command to invoke cron... should it go something like this?

#!/usr/bin/perl
print "Conent-type: text/plain\n\n";

# check old cron jobs
print qq/crontab -l/;

# set new cron job where foo.cron has the crontab info
print qq/crontab -e foo.cron/;

What I've tried doesn't seem to be working... but then again perhaps the hosting account I'm testing on doesn't allow access to cron. Not sure.

amoore

3:20 am on Jan 19, 2002 (gmt 0)

10+ Year Member



crontab -e will erase your crontab file.
I'm pretty sure that if you remove the "-e" it will use your file as your new crontab (and not return any text).
This assumes you have permission to have a crontab, alter that user's crontab, and such.
(this is the case with my version of Vixie cron, that is.)

Also, see the Set::Crontab module from CPAN.

volatilegx

4:13 pm on Jan 21, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks... I hadn't heard of the Set::Crontab module... It could have been the -e switch that was screwing me up... I had thought you needed to use the -e switch so you didn't overwrite the old crontab file.

amoore

6:14 pm on Jan 21, 2002 (gmt 0)

10+ Year Member



You will overwrite the old crontab file.
I thought that was the point.
Otherwise, if you use no "-e" and no filename you will invoke the editor. That's probably vi, and I doubt that's what you want.

What I would do is "crontab -l" to get the crontab, then add my line, then put it back into crontab with no "-e" and a filename.

Try this stuff from the command line so that you see how it works before you erase your crontab through a webpage.

volatilegx

6:51 pm on Jan 21, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks