[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Need cron job to delete files every month first week Saturday.

Posted on 2011-10-17
3
Medium Priority
?
408 Views
Last Modified: 2013-12-16
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.
0
Comment
Question by:Maddy
3 Comments
 
LVL 3

Assisted Solution

by:saimazz
saimazz earned 300 total points
ID: 36984181
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:

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

Open in new window


Then run the wrapper every Saturday: "0 0 * * 1 wrapper"
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 36984869
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
0
 

Author Closing Comment

by:Maddy
ID: 37137539
As always wmp rocksssssssss
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Suggested Courses
Course of the Month18 days, 1 hour left to enroll

830 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