LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   One issue with Crontab (http://www.linuxquestions.org/questions/linux-server-73/one-issue-with-crontab-4175427948/)

abhitanshu 09-19-2012 02:46 AM

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

34 07 * * * /tmp/Script.sh >/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.

Thanks.

druuna 09-19-2012 03:22 AM

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

http://www.ducea.com/2008/11/12/usin...ontab-entries/ (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 04:07 AM

Thanks,
It worked.

tgs78 09-24-2012 03:34 PM

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

<moderated>

Hope you will find this post useful !


All times are GMT -5. The time now is 07:24 AM.