黑帽联盟

 找回密码
 会员注册
查看: 2379|回复: 0

[脚本语言] 利用case语句和shell函数联合开发http启动脚本

[复制链接]

302

主题

18

听众

1012

积分

管理员

Rank: 9Rank: 9Rank: 9

  • TA的每日心情
    郁闷
    4 天前
  • 签到天数: 410 天

    [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


    效果图:

    httpd脚本

    httpd脚本

    您需要登录后才可以回帖 登录 | 会员注册

    发布主题 !fastreply! 收藏帖子 返回列表 搜索
    回顶部