开发者

script working manually but not via crontab?

Wondered if anyone had any idea why the following problem is occurring, or had any tips where to look…I can run the shell script manually in ssh, but if I set it up to run in crontab i get the problems below.

Server is: FreeBSD 8, and I have access to all root permissions

I have a shell script (Bourne) that runs under the “root” permissions using crontab with the following command:

* * * * * /data/backups/scripts/server_log_check.sh > /data/backups/logs/cron_logs/server_log_check.sh_cron.log

The “server_log_check.sh” script checks to see if “the report server” is running with this command:

if ps -xauww | grep -v grep | grep java | grep www > /dev/null
            then 
   开发者_JAVA技巧                         #“reports are running, no need to try to restart it”
            Else
                            /usr/local/etc/rc.d/tomcat55 start     #start report server because it is not running
            Fi

The problem is occurring on this line: “/usr/local/etc/rc.d/tomcat55 start”, when the script is run using crontab, but if I run the script manually via ssh this line of code runs without a problem, but all the rest of the code in the script executes fine, just not this line. Allternatively, if I paste this line /usr/local/etc/rc.d/tomcat55 start into the ssh command prompt, it runs just fine too.

I changed the “server_log_check.sh” ownership to be “root”, but that didn’t make a difference, and the script "tomcat55" ownership is "www". The crontab entry is being made under the "Root" profile, so, I assumed there is no problem running a file that is owned by a lessor permission such as "www" has

Do you have any ideas why cron is doing this?

Thanks in advance


Try adding the following which will add the error to the log file as well:

* * * * * /data/backups/scripts/server_log_check.sh > /data/backups/logs/cron_logs/server_log_check.sh_cron.log 2>&1

Also change this:

/usr/local/etc/rc.d/tomcat55 start  

to:

cd /home/root

nohup /usr/local/etc/rc.d/tomcat55 start &

This should create a nohup.out in /home/root.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜