[root@localhost textshall]# vim zhuoye1.sh
num=`ps -ef | grep httpd | wc -l`
if [ $num -gt 1 ];then
echo httpd is running
else
systemctl restart httpd > /dev/null
echo httpd is running for you
fi
[root@localhost textshall]# bash zhuoye1.sh
🔐 Enter TLS private key passphrase for www.openlab.com:443 (RSA) : ****
httpd is running for you
[root@localhost textshall]#
[root@localhost textshall]# bash zhuoye1.sh
httpd is running
查看端口
[root@localhost textshall]# vim zhuoye1.sh
num=`ss -lntup | grep -w 443 | wc -l`
if [ $num -gt 0 ];then
echo httpd is running
else
systemctl restart httpd > /dev/null
echo httpd is running for you
fi
[root@localhost textshall]# bash zhuoye1.sh
🔐 Enter TLS private key passphrase for www.openlab.com:443 (RSA) : ****
httpd is running for you
[root@localhost textshall]#
[root@localhost textshall]# bash zhuoye1.sh
httpd is running
2、使用curl命令访问第二题的web服务,看能否正常访问,如果能正常访问,则返回web server is running;如果不能正常访问,返回12状态码。
[root@localhost ~]# vim curl.sh
curl www.openlab.com &> /dev/null
if [ $? -eq 0 ];then
echo web is running
else
exit 12
fi
[root@localhost ~]# bash curl.sh
web is running
[root@localhost ~]#