cancel
Showing results for 
Search instead for 
Did you mean: 

cron issue

Muhammad Ahmad
Frequent Advisor

cron issue

Hi,

Good Day

we create a cron entry in an ordinary user account, like given below:

* * * * * /tmp/scr.sh > /tmp/scr.log

when above executes, the scr.log always found empty?

Given below tests have been performed to diagnose/resolve:

1. execute /tmp/scr.sh manually through ordinary user account, all the commands sequentially executes without any problem.

2. we have replaced already written commands in scr.sh file with a single command like echo 'test-output' > /tmp/echo.out. and then run 'scr.sh' through cron; strangly it also run without any problem which is confusing me.

Now, some questions arose:

Why an echo command is executing through cron in scr.sh and the other commands NOT?

Why other commands are running without any problem when running on CLI like

chmod +x /tmp/scr.sh
/tmp/scr.sh

it runs fine, but through cron it won't?


Regards,
Muhammad Ahmad
5 REPLIES
SUDHAKAR_18
Trusted Contributor

Re: cron issue

Hi,

Can you try this..

* * * * * /tmp/scr.sh >> /tmp/scr.log

use append (>>) instead of diversion (>)
Yogesh M Puranik
Valued Contributor

Re: cron issue

Hi,

Your checks :

1]Check cron daemon is working properly, by using other simple test script.

2]Arrange the cron entry as mentioned below,so that you will get the details of errors you will get while excuting.

***** /tmp/scr.sh 2>>/tmp/scr.log.

3]Check the shell you are keeping as a magic line while starting the script.

3]Check whther you ve any line which clears executable logs.

Please check and let me know result as well as share script contents to check.


Rgds

Yogesh


Ganesan R
Honored Contributor

Re: cron issue

Hi Muhammad,

If you want to redirect the standard output and standard errors produced by the script to a file, you should use like below.

* * * * * /tmp/scr.sh > /tmp/scr.log 2>&1

or to avoid overwrite

* * * * * /tmp/scr.sh >> /tmp/scr.log 2>&1
Best wishes,

Ganesh.
Dennis Handly
Acclaimed Contributor

Re: cron issue

>when above executes, the scr.log always found empty?

It is possible you don't have PATH set properly for the command you want to execute, so you get no output. cron has a limited PATH. That's why it works when you do it manually.
Proboi
Advisor

Re: cron issue

Hi Muhammad,
As a test Spaces can be safely removed and if there is a problem executing you can also redirect the error message to the file

please try executing the following command via command line and check if it works

sh -x /tmp/scr.sh>>/tmp/scr.log

this way you can confirm if there are any error that occurred executing the command

then could you try the following please

* * * * * /tmp/scr.sh>>/tmp/scr.log 2>&1