Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Why this script doesn't work in the cron for root or other user and generates a empty output ?

/tmp/test-1.log
---------------
#!/bin/sh
/bin/echo this is test-1.sh
/bin/date "+%FT%T"

Permissions are ok

# ls -l /root/test-*
-rwxr-xr-x 1 root root 58 Apr 27 22:48 /root/test-1.sh
#

Cron line crontab -e. I had tried these 2 ways, creating and appending

55 * * * * /root/test-1.sh &>  /tmp//tmp/test-1.log
58 * * * * /root/test-1.sh &>> /tmp//tmp/test-2.log

and output is empty, why !!!!!!

# date; ls -ld /tmp/test*
Sun Apr 27 22:59:56 CEST 2014
-rw-r--r-- 1 root root 0 Apr 27 22:55 /tmp/test-1.log
-rw-r--r-- 1 root root 0 Apr 27 22:55 /tmp/test-2.log
# 

What's it wrong ? It must be something simple but I cann't found it.

By the way I'm using Ubuntu 12.04.4 LTS.

share|improve this question
    
thanks to girardengo and L. D. James, you are right. The right syntax for redirecting stdout and stderr to a file is: ` 55 * * * * /root/test-1.sh > /tmp//tmp/test-1.log 2>&1 58 * * * * /root/test-1.sh >> /tmp//tmp/test-2.log 2>&1 ` Regards –  user275119 Apr 28 at 17:46

2 Answers 2

Try changing the line in the crontab with this:

55 * * * * /bin/sh /root/test-1.sh > /tmp/test-1.log
58 * * * * /bin/sh /root/test.2.sh >> /tmp/test-2.log

this should solve the problem.

share|improve this answer

Your redirect syntax is flawed.

Change your crontab to:

55 * * * * /root/test-1.sh >  /tmp/test-1.log
58 * * * * /root/test-1.sh >> /tmp/test-2.log
share|improve this answer
    
I see girardengo has given you the answer while I was testing the output. But as he mentioned, the updated lines will work. –  L. D. James Apr 27 at 22:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.