用case分支语句控制apache服务的实例
[root@ChangerLee 控制结构]# cat case_httpd.sh
#!/bini/bash
#this is an apache command
[ -f /etc/init.d/functions ] && . /etc/init.d/functions||exit 1
if [ $# -ne 1 ]
then
echo "Usage:case_httpd.sh start|stop|restart"
exit 1
else
case "$1" in
"start")
systemctl start httpd.service
sleep 1
action "apache is running." /bin/true
;;
"stop")
systemctl stop httpd.service
sleep 1
action "apache is stop." /bin/true
;;
"restart")
systemctl restart httpd.service
action "apache is running." /bin/true
esac
sleep 1 && netstat -antple|grep httpd
fi
[root@ChangerLee 控制结构]# sh case_httpd.sh start
apache is running. [ OK ]
tcp6 0 0 :::80 :::* LISTEN 0 1181108 29104/httpd
tcp6 0 0 :::443 :::* LISTEN 0 1181116 29104/httpd
[root@ChangerLee 控制结构]# sh case_httpd.sh stop
apache is stop. [ OK ]
[root@ChangerLee 控制结构]# sh case_httpd.sh restart
apache is running. [ OK ]
tcp6 0 0 :::80 :::* LISTEN 0 1194047 30430/httpd
tcp6 0 0 :::443 :::* LISTEN 0 1194055 30430/httpd