还得我想了10分钟才明白”!=“和"-n"的用法区别,做个笔记捋一捋
第一种方法:测试apache是否开启?字符串测试
#!/bin/bash
web=`/usr/bin/pgrep httpd`
if [ -n "$web" ]; //$web返回值是否为空
then
echo "httpd is running"
else
/etc/init.d/httpd start
fi
第二种:
#!/bin/bash
web=`/usr/bin/pgrep httpd`
if [ "$web" !=“” ]; //$web返回值是否等于空
then
echo "httpd is running"
else
/etc/init.d/httpd start
fi