Operating System - HP-UX
1844183 Members
2536 Online
110229 Solutions
New Discussion

cron and date command options for output

 
SOLVED
Go to solution
Jay W. Smith
New Member

cron and date command options for output

I'm doing a make_tape_recovery backup from cron and I want the output to go to a file with the date at the end.

I'd like the date format to be Year Month Day as numbers like the following:
"20040229"

I can't seem to get it to work and I think it may be a bug in cron.

Here's my command in cron:
10 15 24 2 * /opt/ignite/bin/make_tape_recovery -AIv > /home/js4519su/mtr_out.$(/usr/bin/date +%Y%m%d)

This work when I perform the command outside of cron. It also works for "at" however, in cron, the file gets named as follows:

"/home/js4519su/mtr_out."

When I do it outside of cron or in "at" the file name is created as expected:

"/home/js4519su/mtr_out.2004"

Any ideas????
5 REPLIES 5
Patrick Wallek
Honored Contributor

Re: cron and date command options for output

Try setting the date to a variable and then use the variable in the file name.
I would do a little script for the whole thing:

DATE=$(/usr/din/date +%Y%m%d)
FILE=/home/js4519su/mtr_out.${DATE}
/opt/ignite/bin/make_tape_recovery -AIv > ${FILE}

Then put the name of your script as the cron entry.
Charlie Rubeor
Frequent Advisor

Re: cron and date command options for output

cron makes special use of the percent sign. Try $(/usr/bin/date +\%Y\%m\%d), should work fine.
Jeroen Peereboom
Honored Contributor

Re: cron and date command options for output

Or use /usr/bin/date "+%Y%m%d") (with ").

JP
Jay W. Smith
New Member

Re: cron and date command options for output

The /usr/bin/date + \%Y\%m\%d worked.

Thanks,

Jay
Charlie Rubeor
Frequent Advisor
Solution

Re: cron and date command options for output

Please assign points. I need them.