Tuesday, January 11, 2011

Debug a Shell Script and Fix Cron Not Running Problem

How to debug a shell script under Linux or Unix?
http://www.cyberciti.biz/tips/debugging-shell-script.html


How to check shell script syntax without executing it? 
do "sh -n script-name.sh"
or "set -n" inside the script


A user's cron job didn't run, no error message found in the /var/log/cron file?
1 check if "crond" system process is running or not
ps -ef |grep cron


2 chkconfig --list|grep cron
Make sure crond is running at run level 2345


(29.5. chkconfig)
#chkconfig --level 2345 crond on


--Restart cron service if it's not running:

# /etc/init.d/crond restart







3 check /etc/cron.allow file to make sure the username is listed. The format should be like:
#more /etc/cron.allow
user1
user2
user3
Note: don't put an entry like "user1,user2,user3" in the /etc/cron.allow file


4 check /etc/cron.deny to make sure that the username is not listed in this file


Note: if an error like "ERROR: failed to open PAM security session: Success" recorded in /var/log/cron file, please following the instruction listed in this article to resolve this error. 


5 check /etc/pam.d/crond file to make sure it has correct entries

/etc/pam.d/crond file should contain the following lines:
auth sufficient pam_rootok.so
auth required pam_env.so
auth include system-auth
#account sufficient pam_rootok.so
account required pam_access.so
account include system-auth
session required pam_loginuid.so
session include system-auth
Check the commented line #account sufficient pam_rootok.so and if you see this line in there and uncommented the comment it out.

6 check /etc/security/access.conf file to make sure it has correct entries

check the /etc/security/access.conf file and if you see at the end of this file anything that is uncommented like:
-:ALL EXCEPT root:LOCAL
+ : ALL : cron crond
then comment this two lines also.


7 If "crontab -e" still not working, check the sticky bit setting of /usr/bin/crontab


Non Root Users Are Unable To Create Crontab Entries [ID 1268765.1]



[root@db01~]# ls -l /usr/bin/crontab
-rwxr-xr-x 1 root root 311352 Dec 18  2009 /usr/bin/crontab
[root@db01~]# chmod +s /usr/bin/crontab
[root@db01 ~]# ls -l /usr/bin/crontab
-rwsr-sr-x 1 root root 311352 Dec 18  2009 /usr/bin/crontab

Labels: ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home