case语句--shell

7 篇文章 0 订阅
case  $1 in
    word1 )
    action1
    ;;
    word2)
    action2
    ;;
    ........
    *)
    action_last
esac

实验1:服务的查看

9 #!/bin/bash
 10 case $1 in
 11         status)
 12         systemctl $1 $2
 13         ;;
 14 
 15         start)
 16         systemctl $1 $2
 17         ;;
 18 
 19         stop)
 20         systemctl $1 $2
 21         ;;
 22 
 23         *)
 24         echo inupt error
 25         ;;
 26 esac

执行脚本

[root@server210 mnt]# sh case.sh status httpd
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
   Active: activating (start) since Fri 2018-03-09 07:21:52 EST; 30s ago
 Main PID: 1967 (httpd)
   CGroup: /system.slice/httpd.service
           └─1967 /usr/sbin/httpd -DFOREGROUND

Mar 09 07:22:12 server210 httpd[1967]: AH00557: httpd: apr_sockaddr_info_ge...0
Mar 09 07:22:12 server210 httpd[1967]: AH00558: httpd: Could not reliably d...e
Hint: Some lines were ellipsized, use -l to show in full.
[root@server210 mnt]# sh case.sh start httpd
[root@server210 mnt]# sh case.sh status httpd
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
   Active: active (running) since Fri 2018-03-09 07:22:32 EST; 3s ago
 Main PID: 1967 (httpd)
   Status: "Processing requests..."
   CGroup: /system.slice/httpd.service
           ├─1967 /usr/sbin/httpd -DFOREGROUND
           ├─1984 /usr/sbin/httpd -DFOREGROUND
           ├─1985 /usr/sbin/httpd -DFOREGROUND
           ├─1986 /usr/sbin/httpd -DFOREGROUND
           ├─1987 /usr/sbin/httpd -DFOREGROUND
           └─1988 /usr/sbin/httpd -DFOREGROUND

Mar 09 07:22:12 server210 httpd[1967]: AH00557: httpd: apr_sockaddr_info_ge...0
Mar 09 07:22:12 server210 httpd[1967]: AH00558: httpd: Could not reliably d...e
Mar 09 07:22:32 server210 systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值