View Full Version : Crontab alternatives?
Lo guys, i've got a shell account but the admin has disabled access to the crontab. Does anyone know of any alternatives to the crontab? Maybe a program that runs in the background?
Godin had a go in perl and his script turned out to use 80% of the proccessor :)
Gwil Da Skank Of TA
18-04-2001, 00:49
rofl 80% :P
mmmmmm a program a bit like cron :O
got me there.....
try running a search on freshmeat ( http://freshmeat.net ) - if that turns up nothing then ask Godin again :P
nope... can't find anything suitable :|
Ok, two basic ways of doing this. Firstly, you can script
something (Perl would be ideal) which runs in the background. The important thing to remember here is to make the process sleep in between doing things - not busy wait. If you busy wait, you'll eat up all the CPU time doing nothing useful.
This is quite easy to do if you just want something run at equal intervals, it is somewhat harder if you want the full scheduling and output-handling features of cron.
One thing to remember is that if your admin has denied you access to cron then s/he may have an objection to you doing this.
The second approach you could use is to schedule the job with 'at' and have it reschedule itself whenever it runs. This has the advantage that it shouldn't be killed off by a reboot (as the first approach would). However, it is somewhat nastier in concept, and if your admin has turned put you in cron.deny, he may well have put you in at.deny too.
HTH,
AEF
i just want to run ./stats.sh in my dir every 15 minutes... :)
How do i do this using at or a perl script then? :)
Ok, create a file called run_stats.pl containing the following (ignore the <<<< and >>>> cut marks, obviously.)
(I haven't tested this but it should work ok. You could also do this with a shell script, but I like Perl.)
>>>>>>>>>>>>>>>>>
#!/usr/bin/perl -w
# Or maybe /usr/local/bin/perl in previous line, it depends.
# This script needs to be run in the background in your
# home directory.
open O, ">run_stats.pid"; # Put the process ID in a file
print O "$$\n"; # in your home directory so you
close O; # can kill this easily.
while ( 1 ) # Forever
{
system("stats.sh"); # Run script
sleep(900); # Sleep 15m (900 seconds)
};
# That's all, folks!
<<<<<<<<<<<<<<<<<
Then, from your shell prompt:
cd ~
chmod u+x run_stats.pl
Then, to run it:
cd ~
./run_stats.pl &
(This'll work with bash, some shells need you to use nohup when running it.)
Or to stop it:
cd ~
kill `cat run_stats.pid`
It'll stop if the machince reboots, you'll need to start it again manually if this happens.
Be aware that when this script runs stats.sh, it'll wait for stats.sh to finish before continuing. So, if stats.sh takes a non-trivial amount of time to run, you may want to take that time off of the 900 second delay.
Of course, this also assumes that stats.sh is in your home directory, is executable, etc.
HTH,
AEF
Bah. It's destroyed all my whitespace formatting/indentation. Should still work, though.
AEF
Actually, it has broken something - you need backticks in the command to stop it running, not single quotes. (Normally above your 'tab' key.)
AEF
aef - Can i borrow your sandals when you've finished with them :E
Originally posted by Slime
aef - Can i borrow your sandals when you've finished with them :E
*slap*
But I do have a beard.
AEF
Gwil Da Skank Of TA
18-04-2001, 18:41
oooh beard :D
stubble faced geek as lxf puts it :/
u need a nerf gun as well :D
vBulletin® v3.7.4, Copyright ©2000-2008, Jelsoft Enterprises Ltd.