Linux脚本启动,停止,重新启动 [英] Linux script start,stop,restart

查看:109
本文介绍了Linux脚本启动,停止,重新启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我此脚本的确切作用吗?

Can anyone please tell me what exactly this script does?

#! /bin/sh
test –f /usr/bin/sshd || exit 0
case "$1" in
    start)
            echo –n "Starting sshd: sshd"
            /usr/sbin/sshd
            echo "."
            ;;
   stop) 
          echo –n "Stopping sshd: sshd"
          kill `cat /var/run/sshd.pid`
          echo "."
           ;;
   restart)
          echo –n "Stopping sshd: sshd"
          kill `cat /var/run/sshd.pid`
          echo "."
          echo –n "Starting sshd: sshd"
            /usr/sbin/sshd
            echo "."
            ;;
        *)
          echo "Usage: /etc/init.d/sshd start|stop|restart"
          exit 1
          ;;
    esac

我想知道这部分到底是什么:

I want to know what exactly this part:

#! /bin/sh
test –f /usr/bin/sshd || exit 0
case "$1" in
    start)
            echo –n "Starting sshd: sshd"
            /usr/sbin/sshd
            echo "."
            ;;

是因为其他部分相同! 请;)

does because the other part is the same! Please ;)

推荐答案

其他哪个部分相同?脚本的工作方式是检查$1的值,该值是命令行上提供的脚本的第一个参数.如果是开始",则执行start)之后的部分.如果是停止",则执行stop)之后的部分.如果是重新启动",则执行restart)之后的部分.

Which other part is the same? The way that script works is it checks the value of $1, which is the first parameter to the script supplied on the command-line. If it's 'start', then the part after start) is executed. If it's 'stop', then the part after stop) is executed. If it's 'restart', then the part after restart) is executed.

第一部分的一行一行:

#! /bin/sh

嘿,这是一个shell脚本!具体来说,请使用sh shell执行该脚本.

Hey, it's a shell script! Specifically, execute this script using the sh shell.

test –f /usr/bin/sshd || exit 0

是否有一个名为/usr/bin/sshd的文件?如果不是,则返回0退出状态.

Is there a file called /usr/bin/sshd? If not, exit with a 0 return status.

case "$1" in

检查第一个命令行选项$1的值.

Check the value of $1, the first command-line option.

    start)

如果$1是开始" ...

If $1 is 'start'...

            echo –n "Starting sshd: sshd"

打印"Starting sshd: sshd".

            /usr/sbin/sshd

执行/usr/sbin/sshd.

            echo "."

打印".".

            ;;

退出case语句.

这篇关于Linux脚本启动,停止,重新启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆