TA的每日心情 | 难过 2024-11-13 00:16 |
---|
签到天数: 370 天 [LV.9]以坛为家II
|
#!/bin/bash
#用shell写一个脚本去启动httpd服务
#定义一些变量来接收脚本的路径
httpd="/etc/init.d/httpd"
#判断/etc/init.d/functions文件是否存在
[ -f /etc/init.d/functions ] && . /etc/init.d/functions || exit 1
#定义相关函数
start() {
$httpd start >& /dev/null
[ $? -eq 0 ] && action "httpd is started" /bin/true || \
action "httpd is started" /bin/false
}
stop() {
$httpd stop >& /dev/null
[ $? -eq 0 ] && action "httpd is stoped" /bin/true || \
action "httpd is started" /bin/false
}
#用case条件语句来判断httpd服务如何来执行
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 2
start
;;
*)
echo "Usage:$0 {start|stop|restart}"
exit
;;
esac
效果图:
|
|