重启服务crontab的问题 [英] restart service crontab problem

查看:221
本文介绍了重启服务crontab的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我从下面腻子手动运行该脚本(根),然后重新启动该服务没有问题。

手动命令

  SH /home/auser/server/reService.sh>> /var/log/reService.log

但是,如果相同的脚本被计划为一个cronjob,也正在根:

crontab命令

  00 07 * * * /home/auser/server/reService.sh 2  - ;&放1 GT;> /var/log/reService.log

那么服务为myService重启'没有成功执行:不重新启动服务,并在预定的日志中没有命令的输出比手动日志。我也可以告诉你,如果没有如期重启行执行后。

为什么,我错过了一些特权通过crontab的时候去?我怎样才能成功地重新安排的为myService?

感谢提前。

reService.sh

 #!/斌/庆典
明确
回声================================================ =============================
回声我的服务的每日重启
日期
回声================================================ =============================
服务为myService重启
退出0

手动日志

  [H [J ================================== ===========================================
我服务的每日重启
周四5月19日4点51分12秒EDT 2011
================================================== ===========================
停止为myService ..done
开始为myService ..done

定日志

  ====================================== =======================================
我服务的每日重启
周四5月19日7点00分02秒EDT 2011
================================================== ===========================


解决方案

<击>在手动例中使用 SH 的意味着脚本没有执行允许。尝试设置的或在crontab中调用以同样的方式SH(我preFER前)。

修改:OK,这不是权限。看看接下来的事情是$ PATH;呼应的日志文件并进行比较。

EDIT2 :如果PATH是问题,那么就设置它的crontab中:

<$p$p><$c$c>PATH=/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin/:/usr/local/sbin:/usr/bin/X11:/usr/‌​openwin/bin:/usr/java/bin:/root/bin00 07 * * * /home/auser/server/reService.sh 2 - ;&放大器1为卤素;&GT; /var/log/reService.log

if i run the script below manually from putty (as root) then the service is restarted no problem

manual command

sh /home/auser/server/reService.sh >> /var/log/reService.log

But if the same script is scheduled as a cronjob, also under root:

crontab command

00 07 * * * /home/auser/server/reService.sh 2>&1 >> /var/log/reService.log

then the 'service myService restart' is not executed successfully: service is not restarted, and no command output in scheduled log compared to manual log. I can also tell you that nothing after the restart line executes if scheduled.

Why, am I missing some privileges when going through crontab? How can i successfully schedule restarting of myService?

thanks ahead.

reService.sh

#!/bin/bash
clear
echo "============================================================================="
echo "Daily restarting of my service"
date
echo "============================================================================="
service myService restart
exit 0

manual log

 [H [J=============================================================================
Daily restarting of my service
Thu May 19 04:51:12 EDT 2011
=============================================================================
Stopping myService   ..done
Starting myService   ..done

scheduled log

=============================================================================
Daily restarting of my service
Thu May 19 07:00:02 EDT 2011
============================================================================= 

解决方案

The use of sh in your manual example implies that the script doesn't have execute permission. Try setting that or calling sh in the same way within the crontab (I prefer the former).

EDIT: OK, it's not permissions. Next thing to look at is $PATH; echo that to the log file and compare them.

EDIT2: If PATH is the issue, then just set it within crontab:

PATH=/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin/:/usr/local/sbin:/usr/bin/X11:/usr/‌​openwin/bin:/usr/java/bin:/root/bin 

00 07 * * * /home/auser/server/reService.sh 2>&1 >> /var/log/reService.log

这篇关于重启服务crontab的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆