1827487 Members
2262 Online
109965 Solutions
New Discussion

Re: cron help

 
Pat Peter
Occasional Advisor

cron help

I have few cron entries that will process some scripts and redirect the output to a log file.

But since the log grows over time I would like to create a separate output for each day

ex-

current entry:

05,25 * * * * exec ksh -c '. ${HOME}/.profile;~/parse.sh >> /log/parse.log'

I would like to have

05,25 * * * * exec ksh -c '. ${HOME}/.profile;~/parse.sh > /log/parse.log_06022006'

Can anyone please help me.

-Pat
5 REPLIES 5
john kingsley
Honored Contributor

Re: cron help

how about:

05,25 * * * * exec ksh -c '. ${HOME}/.profile;~/parse.sh > /log/parse.log_`date +%m%d%Y`'
Darrel Louis
Honored Contributor

Re: cron help

Pat,

Don't forget to redirect with ">>", otherwise the file will be recreated every-time the cronjob starts.

05,25 * * * * exec ksh -c '. ${HOME}/.profile;~/parse.sh >> /log/parse.log_`date +%m%d%Y`'

Darrel
Peter Nikitka
Honored Contributor

Re: cron help

Hi,

and even more - don't forget - as the previous poster, that a %-sign in a crontab-entry has a special meaning and must be escaped.
I think in HP-UX you have to write two percent signs:
05,25 * * * * exec ksh -c '. ${HOME}/.profile;~/parse.sh >> /log/parse.`date +%%m.%%d.%%y`.log

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
spex
Honored Contributor

Re: cron help

It might be cleaner to create and schedule a separate script to handle switching out of your parse.log, as well as other logfiles. Something like:

#!/usr/sbin/sh
DATE=`date +%Y%m%d`
cp /log/parse.log /log/parse.${DATE}.log
cat /dev/null > /log/parse.log

Have the script run just before midnight, so that the date in the filename matches the date of the log's contents.

PCS
Doug O'Leary
Honored Contributor

Re: cron help

Hey;

Personally, I'd put the log inside the script:

Date=$(date +"%y%m%d")
Log=/log/parse_log_${Date}

(
commands to be executed
) >> ${Log} 2>&1

that way the crontab stays a little cleaner...

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html