Append date to a file from CRON

Hi,

I am trying to append date in DAY_Mon_dd_yyyy at the end of a filename from cron.
Cron entry looks as below.
(script to execute) > test_file_`date +"a_%b_%d_%Y"`

File name created after executing the job is test_file_

I am expecting the filename to be something like
test_file_Wed_Feb_13_2008
I tried without double quotes also.

Please help.

Single quote the date format like this:

(script to execute) > test_file_`date +'a_%b_%d_%Y'`

Regards

I just tried and I am getting the file created as test_file_a_

Sorry, I just copied your sample and forgot the "%" before the "a".
It should be:

(script to execute) > test_file_`date +'%a_%b_%d_%Y'`

Regards

Hi,

This is my crontab entry:

53 13 * * * /psoft/u02/oracle10g/cds/ATES/backup_ATES.sh > /psoft/u02/oracle10g/cds/ATES/backup_ATES_`date +'%d'` 2>&1

and I get output like this:

-rw-r--r-- 1 oracle dba 2943 Feb 14 13:53 backup_ATES_

$ echo $SHELL
/usr/bin/sh

Thanks.

Change your cron entry to:

53 13 * * * /psoft/u02/oracle10g/cds/ATES/backup_ATES.sh /psoft/u02/oracle10g/cds/ATES/backup_ATES

and your script to:

#!/usr/bin/sh

OUTFILE=$1

{

<your original script>

} > ${OUTFILE}_`date +%d` 2>&1

Thanks. That worked.

Changing double quotes to single quote not working.

(script to execute) > test_file_`date +"a_%b_%d_%Y"`
Is still generating the output file as test_file_

Also I cannot try the below example.
{

<your original script>

} > ${OUTFILE}_`date +%d` 2>&1

Please suggest any other solution just by changing the cron entry.

echo $SHELL
/bin/ksh

Thanks.

Hi,

Have you tried:

(script to execute) > test_file_`date | awk '{print $3$2$6}'`

The dollar variables are the column display when you execute 'date' in command line.