1.设置执行脚本:
修改/var/spool/cron/root.sh,每1分钟执行/root/cron目录下的jkapache.sh
*/1 * * * * bash /root/cron/jkapache.sh
2.apache自动启动执行脚本
2.1 创建目录/root/cron
2.2 创建脚本jkapache.sh
##脚本 #!/bin/bash #判断指定进程是否存在 result=`ps -ef | grep -w apache | grep -v grep | wc -l` if [ $result -le 0 ]; then #不存在, 重启 /usr/local/apache/bin/apachectl -f /usr/local/apache/conf/httpd.conf -k start else #存在,判断状态 #取进程状态,用来判断是否僵死 val=`ps -aux | grep apache | grep -v grep | awk '{print $8}'` if [ "$val" == "Z" ];then # 取进程ID,用来kill掉进程 pid = `ps -aux | grep apache | grep -v grep | awk '{print $2}'` kill -9 $pid fi fi
linux自动执行脚本如果报 Syntax error near unexpected token,是编码的问题。 解决办法总结两歩:
1:执行 vi -b test.sh
test.sh 即为要执行的脚本
2: 替换:shift+:冒号>输入:%s/^M//g
在末行模式下:
输入:%s/^M//g
^M
符,不是“^”再加上“M”,而是由“Ctrl+v”、“Ctrl+M”键生成的。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。