Can a csh script be made to "Not Execute" the date command in an echo statement

37 Views Asked by At

I have a cron task that captures log files every six hours. We have a post installation script that executes after we do an install and this script builds the crontab. It is a csh script that uses the echo command and the >> redirection operator to add commands to the crontab. This is how the cron task is added to the crontab in the post installation csh script:

echo " 00    00,06,12,18  *  *  *   csh -c 'find last 6 hrs of modified files and tar/zip them' >> crontab

I want to put a date and time in the tar.gz file name so I used "date" like this to create the tar/zip filename:

/mnt/dir1/dir2/archive/filename_${HOST}_`date +/%Y_/%j_/%H_%M`.tar.gz

Unfortunately, the echo command in the post install script executes the date command and my crontab entry ends up with the time of "Right Now" in it (i.e. /mnt/dir1/dir2/archive/filename_hostname_2024_050_16_11.tar.gz). Instead of getting a crontab that creates a new archive file every six hours, I get a cron task that creates a new file every six hours with the same name as the one before.

Is there a way to make the csh 'echo' command not execute the 'date' command?

0

There are 0 best solutions below