-   Linux - Server (
-   -   One issue with Crontab (

abhitanshu 09-19-2012 01:46 AM

One issue with Crontab
I am trying to execute an script using cron and want to capture its logs.

34 07 * * * /tmp/ >/var/tmp/Log/`date +%d%m%Y%H%M%S`_Script.log

But i am getting error as -

/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file

I had tried below options as well but none had worked -

1. Keep timestamp value in a variable and using that and use that TIMESTAMP=`date +%d%m%Y%H%M%S`

2. use $() instead of ` `

3. use "` `"

4. use $({ })

However all these options work perfectly fine manually.


druuna 09-19-2012 02:22 AM

Seen from cron the % is a special character and needs to be escaped (`date "+\%d\%m\%Y\%H\%M\%S"`_Script.log) (search for crontab escape special characters for more)

An even better solution would be to make the creation and filling of the log file part of the script.

abhitanshu 09-19-2012 03:07 AM

It worked.

tgs78 09-24-2012 02:34 PM

An article explaining the Linux cronjob scheduling with the help of examples.


Hope you will find this post useful !

All times are GMT -5. The time now is 01:34 PM.