Operating System - Linux
1830214 Members
1696 Online
109999 Solutions
New Discussion

Re: Cron is not working...

 
SOLVED
Go to solution
praveen..
Super Advisor

Cron is not working...

Hi,
I am able to execute 1 script using #./tmp/script.sh

and can get the desired output on my email.

I want to run this script in every 15 minutes so i made some entries in crontab file

# crontab -e
00,15,30,45 * * * * /tmp/script.sh

But now i am not getting any mail
# ps -ef | grep -i cron
root 3348 1 0 Nov30 ? 00:00:00 crond
root 31075 23905 0 02:34 pts/7 00:00:00 grep -i cron
#

Please suggest
17 REPLIES 17
praveen..
Super Advisor

Re: Cron is not working...

Now I tried with...

* * * * * date > /tmp/cron.test

in crontab file


and it is working fine...


Please suggest
George Liu_4
Trusted Contributor

Re: Cron is not working...

1. add
MAILTO=
to explicitly assign the mail user;

2.
check /var/log/crontab to see your cronjobs had been invoked


George Liu_4
Trusted Contributor

Re: Cron is not working...

correct on my last post.
it should be
/var/log/cron

Stuart Browne
Honored Contributor

Re: Cron is not working...

Does '/tmp/script.sh' rely upon a given PATH being set?

Generally, only a bare-minimum of PATH is set in the cron environment.

Basically, you've got two choices:

1) Make sure the path you require is set within the script.

2) Absolutely-path every command you call.
One long-haired git at your service...
praveen..
Super Advisor

Re: Cron is not working...

#tail -10 /var/log/cron
Dec 15 02:50:01 hostname crond[11336]: (root) CMD (/opt/wlserver/ldm1v4.sh)

I am getting this message on every minutes.

/opt/wlserver/ldm1v4.sh is the script which i am trying to execute using cron.


where i need to add "MAILTO"?

I think path is set because if i give this command..
#/opt/wlserver/ldm1v4.sh

then script is successfully executing.

please suggest
thanks


Stuart Browne
Honored Contributor

Re: Cron is not working...

If you're getting that message every minute, then you're executing that script every minute.

As this isn't "/tmp/script.sh", I don't see how that's relevant.

Now, back to the PATH issue. Executing a command from the command line *IS NOT THE SAME* as having it execute from cron.

The PATH environment variable is different. STDIN, STDOUT and STDERR are different when executed from cron. Lots of things are different when executed from cron.
One long-haired git at your service...
Alpha977
Valued Contributor

Re: Cron is not working...

hello!

i think the syntax is incorrect.
Try first with a classical command, without comma, example:
10 4 1 * * /tmp/script.sh

Then, check if you have cron.allow file.

Bye
Atul Gautam
Valued Contributor

Re: Cron is not working...

Praveen,

Alpha is correct.

The syntax that you have used in the crontab file is incorrect.

The format which Alpha has also mentioned will be ---

15 * * * *
Then restart your crond service and then see if it gets executed or not.....

Also you can check your cron jobs using crontab -l command





Atul
Stuart Browne
Honored Contributor

Re: Cron is not working...

Alpha, Atul, you're both wrong.

There's nothing wrong with a comma-delimited set of minute values. Go back and re-read your man pages.

Also, if using 'crontab -e', the '/etc/crontab' file or '/etc/cron.d/' structure, there's no need to restart 'crond'.
One long-haired git at your service...
praveen..
Super Advisor

Re: Cron is not working...

so please let me know how to ser PATH environment variable


Thanks
Stuart Browne
Honored Contributor

Re: Cron is not working...

2nd line of your script:

PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin"

that sort of thing.

Do 'echo $PATH' in the shell to get what it's currently set to.. copy/paste that in.
One long-haired git at your service...
praveen..
Super Advisor

Re: Cron is not working...

I have set the PATH in my script,
but still that script is not running using cron.

if i execute this script using #./script.sh
, I am getting the correct output.

when i am using cron....even I am not getting any thing in /var/log/maillog

(This script send me the output to my email id)

Please suggest
Stuart Browne
Honored Contributor

Re: Cron is not working...

What's the first line of the script file?
One long-haired git at your service...
praveen..
Super Advisor

Re: Cron is not working...

This script is for to find a process "ldm1v4" whether it is running or not?

if the process is not running, script will send the email. (mailfile is a script to send the emails)

# cat ldm1v4.sh

PATH="/home/db2home/SymphonyRPM/Server/Python23:/home/db2home/SymphonyRPM/Share:/home/db2home/SymphonyRPM/Server/ldap:/home/db2home/SymphonyRPM/Server/stubs::/home/db2home/SymphonyRPM/server:/home/db2home/SymphonyRPM/server/Python23:/home/db2home/SymphonyRPM/share:/home/db2home/SymphonyRPM/server/ldap:/home/db2home/SymphonyRPM/Server/stubs::/usr/local/nz/bin:/opt/CA/SharedComponents/dmscript/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin"
NUM_PROC=$(ps -ef |grep -c ldm1v4)
if [[ $NUM_PROC = 1 ]]
then
/opt/wlserver/mailfile_ldm1v4.sh praveen@hp.com root@hostname.company.com 1 2 `hostname`::wlserver process is running
fi



and I also tried with #!/bin/sh

# cat ldm1v4.sh
#!/bin/sh
PATH="/home/db2home/SymphonyRPM/Server/Python23:/home/db2home/SymphonyRPM/Share:/home/db2home/SymphonyRPM/Server/ldap:/home/db2home/SymphonyRPM/Server/stubs::/home/db2home/SymphonyRPM/server:/home/db2home/SymphonyRPM/server/Python23:/home/db2home/SymphonyRPM/share:/home/db2home/SymphonyRPM/server/ldap:/home/db2home/SymphonyRPM/Server/stubs::/usr/local/nz/bin:/opt/CA/SharedComponents/dmscript/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin"
NUM_PROC=$(ps -ef |grep -c ldm1v4)
if [[ $NUM_PROC = 1 ]]
then
/opt/wlserver/mailfile_ldm1v4.sh praveen@hp.com root@hostname.company.com 1 2 `hostname`::wlserver process is running
fi



If i give the command...
#./ldm1v4.sh

I got the desired result
this script is not working with cron

Please suggest
Stuart Browne
Honored Contributor
Solution

Re: Cron is not working...

That should be working.

Check the messages file for any cron errors, restart crond, ensure that 'crontab -l' shows the right stuff, that the file is actually there and is executeable (+x), that the security policy allows for it to execute outside of a shell (audit.log possibly)...

Time to grasp at straws.
One long-haired git at your service...
George Liu_4
Trusted Contributor

Re: Cron is not working...

At this time, I hope your cronjob works fine.
BUt If it is not, follow the steps below:

1. in file /var/log/cron, check your script/cronjob has been started

2. If not, check your crontab syntax

3. If yes, append ">>& /tmp/cron.log" on the problematic entry of your crontab, and add some debug info in your script

What's your shell? is it bash or csh? The path setting is different.
praveen..
Super Advisor

Re: Cron is not working...

I needed to use...if [[ $NUM_PROC == 1 ]]
while I was using ...if [[ $NUM_PROC = 1 ]]
in my script..


Thanks everybody :-)