Cron job shell script..

Hey Guys,

i was trying out a shell script which has to remove a file for every 90 mins. this is the code i came up with .

$ crontab -e file1

file1 contains

30 1 * * * * rm -r /folder1/folder2/somefile.txt

Now i need the cron to run for every 90 mins. the problem with this is since the first field only accepts 0-59 i assumed it will add up the 30min and 1 hr as 90 mins, which i now think is incorrect. any suggestions ?

thanks
arsenalboy

yeah- that will run at 01:30 every day, not every 90 mins.

you could try running it every 30 mins, and set a flag file - test the age of the file, and if greater than, say 70 mins, run your command and retouch your flag file...

Or set a counter,

Or simply set a sleep timer in there, after which time it re-runs itself...

Or get your script to calculate next run time and reschedule using at

HTH,

if you can install fcron it will support more complex time arguments, if you are forced to use standard cron, try this.

0 0,3,6,9,12,15,18,21 * * * rm -r /folder1/folder2/somefile.txt

*     *   *   *    *  command to be executed
-     -    -    -    -
|     |     |     |     |
|     |     |     |     +----- day of week (0 - 6) (Sunday=0)
|     |     |     +------- month (1 - 12)
|     |     +--------- day of month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)
   

Your entry will run at 1:30 am once a day. 90 minutes requires two separate crontab entries:

0 0,3,6,9,12,15,18,21 * * * [your cmd]

30 1,4,7,10,13,16,19,22 * * * [your cmd]

the [your cmd] is identical in the two entries. Also it is general MUCH better to specify
a shell script to run rather than a command. You simply edit the shell script as the complexity of the requirement morphs. read: users complain

Hi.

I guess this is GNU cron, but would this not work (if you have GNU cron!):

*/90 * * * * .....
man 5 crontab

you mean vixiecron?

Note: Not all crond implementations support the */90 slash syntax. The OP did not specify which one - FWIW.

Hi.

I have no idea what vixiecron is! All I know is that the cron on my CentOS Linux works like this. If that's vixiecron, then freut mich!

crontab -e
 
*/90 * * * * date >> /tmp/cron_date.txt
:wq
crontab: installing new crontab

If it didn't like it, I'm sure it would have complained. I'll tell you in about 85 minutes :slight_smile:

But Jim Mc. is right. People don't often state their OS when they ask the question.

---------- Post updated at 11:18 PM ---------- Previous update was at 06:51 PM ----------

It didn't complain, and it doesn't work! Es freut mich nicht!

Thu Aug  6 20:03:01 UTC 2009
Thu Aug  6 21:00:01 UTC 2009
Thu Aug  6 22:00:01 UTC 2009
Thu Aug  6 23:00:01 UTC 2009
Fri Aug  7 00:00:01 UTC 2009

And what took it so long?

Thu Aug  6 21:00:01 UTC 2009

So much for that!

cron doesn't care how many times you invoke the same script file. So why not invoke it 16 times at the time you want it to run?

0 0 * * * * /usr/bin/cleanup
30 1 * * * * /usr/bin/cleanup
0 3 * * * * /usr/bin/cleanup
.
.
.
30 22 * * * * /usr/bin/cleanup

Without doing some research, and assuming that the SCO I'm familiar with might work differently, I would suspect that the 90 minute sequence of executing might be determined by the time of the last reboot.