2

We have currently setup a cron job for our new script as below:

46 22 * * * /gzm_common/diagbat9/global/prod/chgstatus.sh /backups/diagbat9/Demantra/output/SK_ITEM_EXTRACT_MFGPRO_$(date +%m%d%y).txt

It takes the file with .txt as extension as a parameter. When the cron job executed, the file did not get created. This is what we got of the file at 22:46 pm:

22:46    SK_ITEM_EXTRACT_MFGPRO_

and this is a zero byte file, whereas it should contain a lot of data. Shall I try putting the entire filepath and name in double quotes?

  • Did you get an emails from cron complaining of errors (and if not, is email properly configured on your box so that you would get them, had it sent any?) – derobert Aug 22 '14 at 11:18

1 Answers1

3

You need to escape the percent characters using a backslash:

.../SK_ITEM_EXTRACT_MFGPRO_$(date +\%m\%d\%y).txt

From the crontab(5) man page from the ISC implementation of cron:

The ``sixth'' field (the rest of the line) specifies the command to be run. The entire command portion of the line, up to a newline or % character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the crontab file. Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input. There is no way to split a single command line onto multiple lines, like the shell's trailing "\".

Jan
  • 7,772
  • 2
  • 35
  • 41
  • Thank you so very much for your kind and fast replies, really appreciate it. I have done teh change in our crontab and will wait for the results tomorrow. Will let u know how it goes. – arpita dhote Aug 22 '14 at 12:04
  • Dear Seniors, it worked, its now funtioning perfectly. Many many thanks for your help! – arpita dhote Sep 10 '14 at 10:27