Clicky

Hi experts,

Below is the my corn job Not working :-(. Its deleting file ever Saturday.

0 1 1-7 1-12 6 rm /srv/www/upload_doc/*

My requirement is Every moth first week of Saturday only the files need to be deleted. In above cron stanza what i m missing. pleas help.

Thanks,

sk.

asked 10/17/2011 02:55

sivakumar_experts's gravatar image

sivakumar_experts ♦♦


3 Answers:
This usual solution is something like, first write a wrapper script that will run somecommand only if the day of the month is 7 or less:

1:
2:
3:
4:
5:
6:
#! /usr/bin/ksh
day=$(date +%d)
if ((day <= 7)) ; then
   exec somecommand
fi
exit 1


Then run the wrapper every Saturday: "0 0 * * 1 wrapper"
link

answered

saimazz's gravatar image

saimazz

Or all in one:

0 1 * * 6 [ $(date "+\%d") -le 7 ] &&  rm /srv/www/upload_doc/*

Note the backslash ("\") in front of the percent ("%") sign! It's very important under cron.

If you'd like to test on the command line however, you must remove it, since outside cron it will be considered an error.

wmp
link

answered 2011-10-17 at 23:27:27

woolmilkporc's gravatar image

woolmilkporc

As always wmp rocksssssssss
link

answered 2011-10-18 at 02:03:18

sivakumar_experts's gravatar image

sivakumar_experts

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×1

Asked: 10/17/2011 02:55

Seen: 172 times

Last updated: 11/14/2011 08:51