shell条件测试语句实例-测试apache是否开启
发布时间:2014-12-26 编辑:jiaochengji.com
本文介绍了shell条件测试语句的实例代码,用shell条件测试语句检测apache服务是否开启,有需要的朋友参考下。
终于理解了shell条件测试语句”!=“和"-n"的用法区别,于是有了如下的shell脚本,做为练习。
第一种方法:测试apache是否开启?字符串测试
复制代码 代码示例:
#!/bin/bash
# www.jiaochengji.com
web=`/usr/bin/pgrep httpd`
if [ -n "$web" ]; //$web返回值是否为空
then
echo "httpd is running"
else
/etc/init.d/httpd start
fi
# www.jiaochengji.com
web=`/usr/bin/pgrep httpd`
if [ -n "$web" ]; //$web返回值是否为空
then
echo "httpd is running"
else
/etc/init.d/httpd start
fi
第二种方法:
复制代码 代码示例:
#!/bin/bash
# www.jiaochengji.com
web=`/usr/bin/pgrep httpd`
if [ "$web" !=“” ]; //$web返回值是否等于空
then
echo "httpd is running"
else
/etc/init.d/httpd start
fi
# www.jiaochengji.com
web=`/usr/bin/pgrep httpd`
if [ "$web" !=“” ]; //$web返回值是否等于空
then
echo "httpd is running"
else
/etc/init.d/httpd start
fi
您可能感兴趣的文章:
上一篇:清空系统日志shell脚本实例代码
下一篇:mysql数据库备份脚本一例
[关闭]