1745907 Members
4187 Online
108723 Solutions
New Discussion юеВ

Need Date Stamp in Cron

 
SOLVED
Go to solution
Scott Frye_1
Super Advisor

Need Date Stamp in Cron

I have this entry in cron:
#0,15,30,45 * * * * /home/sysadmin/chifmsystmstats.sh >/home/sysadmin/chifm.html 2>/dev/null

What I need to do is add a date stamp to chifm.html. Is there a way to do this in cron? I tried some date logic but the cron file didn't like it. I tried

Date=`date +%b%d`
chifm.${Date}.html

Any help would be appreciated.

Thanks

Scott
7 REPLIES 7
Ian Dennison_1
Honored Contributor

Re: Need Date Stamp in Cron

Put the output redirection inside your script, with the name of the output file including the variable 'Date'.

(cron entry)
0,15,30,45 * * * * /home/sysadmin/chifmsystmstats.sh 2>/dev/null

(Inside the script /home/sysadmin/chifmsystmstats.sh)

DATE==`date +%b%d`

# Output commands
echo "A B C D E" > >/home/sysadmin/chifm.${DATE}.html

(end comments)

Share and Enjoy! Ian
Building a dumber user
Victor BERRIDGE
Honored Contributor
Solution

Re: Need Date Stamp in Cron

Hi Scott,

Why not simply solving that by a script which calls chifmsystmstats.sh instead of redirecting the output to chifm.html from cron?
In new script:
load all you need
Date=`date +%b%d`
/home/sysadmin/chifmsystmstats.sh >chifm.${Date}.html

etc...
and in crontab
#0,15,30,45 * * * * /home/sysadmin/newscript >>/tmp/newscript.log 2>&1

All the best
Victor
Stephen Keane
Honored Contributor

Re: Need Date Stamp in Cron

Put all your stuff in a script and call the script in cron.


your_script

#! /bin/sh
Date=`date +%b%d`
chifm.${Date}.html
/home/sysadmin/chifmsystmstats.sh > /home/sysadmin/chifm.$(Date).html 2>/dev/null

#0,15,30,45 * * * * your_script
Steven E. Protter
Exalted Contributor

Re: Need Date Stamp in Cron

I would add the following lines of code to the script:

/home/sysadmin/chifmsystmstats.sh

dman=$(date)
echo $dman >> /home/sysadmin/chifrm.html

Insert the code whereever it formats best.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Jan Sladky
Trusted Contributor

Re: Need Date Stamp in Cron

Hi Scott,

you can create "main_script.sh" that will contain following

Date=`date +%b%d`
chifm.${Date}.html

/home/sysadmin/chifmsystmstats.sh >
/home/sysadmin/chifm.${Date}.html 2> /dev/null

then

0,15,30,45 * * * * /home/sysadmin/main_script.sh

it should work

rgds Jan
GSM, Intelligent Networks, UNIX
Fred Ruffet
Honored Contributor

Re: Need Date Stamp in Cron

If you want it directly in cron entry (even if it would be better in script:) you can modify line like this :
0,15,30,45 * * * * /home/sysadmin/chifmsystmstats.sh >/home/sysadmin/chifm.$(/usr/bin/date +%b%d).html 2>/dev/null
(everything on the same line, of course)

regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Scott Frye_1
Super Advisor

Re: Need Date Stamp in Cron

I should have thought of it myself. I'll create a new file that executes the script and includes the date stamp.

Thanks to all!!