首页 > 系统服务 > 详细

六、Shell脚本高级编程实战第六部

时间:2019-10-01 14:11:31      阅读:100      评论:0      收藏:0      [点我收藏+]

一、写一个start_nginx脚本,当启动、停止、重启时利用系统函数模拟实现系统脚本启动的特殊颜色效果 (用if实现)   

#!/bin/sh
. /etc/init.d/functions
if [ $# -ne 1 ]
  then
   echo "USAGE $0 {start|stop|restart}"
   exit 1
fi
if [ "$1" == "start" ]
  then
    action "start nginx" /bin/true
elif [ "$1" == "stop" ]
  then
     action "stop nginx" /bin/true
elif [ "$1" == "restart" ]
  then
     action "restart nginx" /bin/true
else
    echo "USAGE $0 {start|stop|restart}"
    exit 1
fi

结果测试:

技术分享图片

 

二、什么是函数

     简单的说,就是把程序里多次调用的部分定义成一份,然后起个名字,对于所有的调用,用这个名字就可以了。

    优势:减少程序代码量;增加程序的可读、易读性;实现程序功能的模块化

三、用 if 和函数 实现  mysql的启动

  单实例:

        1.启动: mysqld_safe  --user=mysql &

 

 

  

 

六、Shell脚本高级编程实战第六部

原文:https://www.cnblogs.com/dangjingwei/p/11615290.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!