; 31333741@qq.com </tmp/httpd.log
exit 1
else
action "httpd is running" /bin/true
exit 0
fi
真正使用时,有些输出是不需要的就去掉
[root@oldboy-B scripts]# cat apachemon1
#!/bin/sh
#created by oldboy 20110523
#QQ 31333741
. /etc/init.d/functions
wget --quiet --spider http://10.0.0.161/index.htm #=====>这个是基于WGET URL方式进行判断
if [ $? -ne 0 ];then
action "httpd is not running" /bin/false >/tmp/httpd.log
httpdctl restart >/dev/null 2>&1
action "httpd is restart" /bin/true >>/tmp/httpd.log
mail -s "`uname -n`''s httpd restarted at `(date)`" 31333741@qq.com </tmp/httpd.log
exit 1
fi
提示:请同学们详细总结wget命令,做为下周作业提交.
多条件判断的写法
拥有帝国一切,皆有可能。欢迎访问phome.net
[root@oldboy-B scripts]# cat apachemon1
#!/bin/sh
#created by oldboy 20110523
#QQ 31333741
. /etc/init.d/functions
HTTPPORTNUM=`netstat -lnt|grep 80|grep -v grep|wc -l`
HTTPPRONUM=`ps -ef|grep http|grep -v grep|wc -l`
wget --quiet --spider http://10.0.0.161/index.htm && RETVAL=$?
if [ $RETVAL -ne 0 ] || [ $HTTPPORTNUM -ne 1 ] || [ $HTTPPRONUM -lt 1 ] ;then
#if [ "$RETVAL" != "0" -o "$HTTPPORTNUM" != "1" -o "$HTTPPRONUM" < "1" ] ;then
#提示:以上是两个if为多条件判断的写法,建议同学们掌握第一个.
action "httpd is not running" /bin/false
action "httpd is not running" /bin/false >/tmp/httpd.log
httpdctl restart >/dev/null 2>&1
action "httpd is restart" /bin/true
mail -s "`uname -n`''s httpd restarted at `(date)`" 31333741@qq.com </tmp/httpd.log
exit 1
else
action "httpd is running" /bin/true
exit 0
fi
以上为 老男孩 给的课前考试的参考答案,欢迎大家讨论、交流,共同提高进步.
后记:shell编程能力 是衡量linux运维工程师水平的一个重要砝码,因此,要掌握它.. 本文出自 “老男孩的linux博客” 博客,请务必保留此出处http://oldboy.blog.51cto.com/2561410/571066
拥有帝国一切,皆有可能。欢迎访问phome.net |