• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1537
  • Last Modified:

scheduling a cron job to run every hour between 430 pm and 230 am, outputting a file and not overwriting the previous file

I need to schedule a job to run every hour from 430pm till 230am. I need the output of this job to be a text file saved to a certain folder and I need it to create a new file each time and not overwrite the previous hour's file. Can this be done?

Justin
0
forfarj
Asked:
forfarj
1 Solution
 
rdutaCommented:
yes it can.

1) you will need a script to execute and log all your output to a file instead of being e-mailed to you.  Easy enough, just create a shell script and use a timestamp to create filenames such as:
mdate=`date +"%Y-%m-%d-%H-%M-%S-$$"`
in your shell script then you would redirect all IO to that file (stderr and stdout) to that file.

2) you will need two crontab entries:
30 16-23 * * * /path/file.sh
30 0-2 * * * /path/file.sh

remember:
crontab -e ( to edit the crontab )
man 5 crontab (to see the format for the crontab file)

3) caution
If your program takes more than 30 minutes to run, or if it never quits, you might kill your machine by running out of processes.  It would be wise to put a safety check in the script to check for the existence of a already running process, and if found generate a error (ie e-mail)

4) useful
Sometimes you only want to keep the last two weeks of data (or last year, etc..) so it's handy to have the directories pruned every so often.  This comes in handy for that:
/usr/bin/find $DIRS_TO_PRUNE -type f -maxdepth 1 -daystart -mtime +14 -print0
| /usr/bin/xargs -r -0 rm
0
 
michelandreCommented:
to rduta: CQFD, Very nice
0
 
CleanupPingCommented:
forfarj:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
TheWeakestLinkCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept comments from rduta as answer
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheWeakestLink
EE Cleanup Volunteer
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now