Question

Good Morning All,

I'm currently having an issue with running a bash script in Crontab on my CentOS 6.5 system. I believe that I have all of the permissions set correctly for the bash scripts and the scripts are set to be executable.

Basically, I'd like to run the below scripts 4 times a day for each model run (00Z, 06Z, 12Z, 18Z) and I thought that I had that setup correctly but, apparently not.

Here's what I have set in crontab (via the " crontab -e"):

40 02 * * * /home/muaddib/grads/get_nomads/bash/nam4.sh
30 08 * * * /home/muaddib/grads/get_nomads/bash/nam4.sh
15 14 * * * /home/muaddib/grads/get_nomads/bash/nam4.sh
20 20 * * * /home/muaddib/grads/get_nomads/bash/nam4.sh

40 02 * * * /home/muaddib/grads/get_nomads/bash/nam12.sh
30 08 * * * /home/muaddib/grads/get_nomads/bash/nam12.sh
15 14 * * * /home/muaddib/grads/get_nomads/bash/nam12.sh
20 20 * * * /home/muaddib/grads/get_nomads/bash/nam12.sh

39 02 * * * /home/muaddib/grads/get_nomads/bash/gfs_sflux_t2m.sh
30 08 * * * /home/muaddib/grads/get_nomads/bash/gfs_sflux_t2m.sh
15 14 * * * /home/muaddib/grads/get_nomads/bash/gfs_sflux_t2m.sh
48 22 * * * /home/muaddib/grads/get_nomads/bash/gfs_sflux_t2m.sh

I tried to run them last night but, nothing happened...

Any thoughts?

Was it helpful?

Solution

1) Check mail after login as muaddib,

su - muaddib
mail

It gives you the error message from cronjob and you should find out what's the reason.

2) The common problem in cronjob is, you need provide full path for each command in script, or run the script in cronjob as:

20 20 * * * ~/.profile; bash /home/muaddib/grads/get_nomads/bash/nam4.sh

If the script is written under bash

OTHER TIPS

Were you able to run these script successfully standalone?

There is possibility that your script needs application specific 'Environment variables' for eg. "LD_LIBRARY_PATH"

Also, you can try with simple test script that will echo some text in test.txt file and include it in crontab. If it runs you will be sure that there is not an issue with crontab.

Let us know if this works!

I spent about 2 hours trying to figure this out myself, maybe it'll help someone else.

Just because your script is /home/user/scripts/script.sh and in your crontab you call that script by the absolute path, doesn't mean that's the path that the script is actually running in. I found the output of my script in /home/user, which makes some sense in retrospect. Make sure if the script you're calling is generating output that you specify the full path to the output inside the script as well (or cd to the correct path at the top of the script).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top