?
Solved

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

Posted on 2003-03-24
4
Medium Priority
?
1,529 Views
Last Modified: 2009-02-10
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
Comment
Question by:forfarj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 1

Accepted Solution

by:
rduta earned 2000 total points
ID: 8198048
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
 
LVL 1

Expert Comment

by:michelandre
ID: 8200011
to rduta: CQFD, Very nice
0
 

Expert Comment

by:CleanupPing
ID: 9087624
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
 
LVL 2

Expert Comment

by:TheWeakestLink
ID: 9289698
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 Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

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 …
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses
Course of the Month8 days, 6 hours left to enroll

766 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