服务器:centos 5
idia是在服务器上设置自动作业,以使httpd的服务从1:00am
开始到3:00 pm
,服务应该停止的剩余时间。
是否可以在服务器上安装可自动运行此作业的脚本,而无需手动操作:
sudo service httpd start
sudo service httpd stop
表示提及作业应该在脚本上
到目前为止,我已经使用过:
crontab -e
在crontab上添加了下面的行
00 03 * * * bush /scripts/stop.sh
这是/script/stop.sh中 stop.sh 脚本的代码
sudo service httpd stop
但仍然没有结果意味着httpd服务处于启动状态。
问候
答案 0 :(得分:2)
设置cron作业。 man crontab
了解更多信息。登录后输入crontab -e
。对于httpd
从凌晨1:00 开始并在凌晨3:00停止(crontab内容)的情况:< / p>
00 01 * * 1,2,3,4,5 /usr/sbin/sudo /sbin/service httpd start
00 03 * * 1,2,3,4,5 /usr/sbin/sudo /sbin/service httpd stop
如果您已完成添加crontab
行,请使用:wq
编写contab并退回到shell。然后你应该看到:
crontab: installing new crontab
答案 1 :(得分:0)
我发现这是一个解决方案:
首先我们需要添加 crontab 的路径 编辑crontab并添加以下行:
crontab -e
添加:
PATH=/usr/sbin:/usr/bin:/sbin:/bin
01 01 * * * service httpd start
01 15 * * * service httpd stop
和centos上的任何其他服务相同。