zoukankan      html  css  js  c++  java
  • Linux学习之十七-配置Linux简单的脚本文件自启动

    配置Linux简单的脚本文件自启动

    在Linux中使用shell脚本解决一些问题会比单独执行多条命令要有效率,脚本文件规定命名以.sh结尾,最基本的规则就是其内容是命令,想要脚本文件开机自启动,就需要把脚本文件放到/etc/init.d/目录下,此目录下的脚本文件是开机自启动脚本,脚本文件执行的基本要求是把命令单独放到命令行执行不会报错

    1、执行命令cat /etc/init.d/sshd查看脚本文件

    [root@localhost ~]# cat /etc/init.d/sshd

    #!/bin/bash    #指定脚本解释器的类型

    #

    # sshd        Start up the OpenSSH server daemon

    #

    # chkconfig: 2345 55 25        

    #2345表示执行chkconfig命令时的默认修改运行级别

    #55表示启动顺序

    #25表示关闭顺序

    # description: SSH is a protocol for secure remote shell access.

    # This service starts up the OpenSSH server daemon.

    #

    # processname: sshd

    2、自定义开机启动脚本的步骤

    基本思路:编写脚本文件,然后为脚本文件添加可执行权限,最后将脚本文件添加到开机启动的服务中去即可

    [root@localhost ~]# touch /etc/init.d/ceshijiaoben         #创建脚本文件

    [root@localhost ~]# vim /etc/init.d/ceshijiaoben                #编辑脚本文件

    #!/bin/bash

    #chkconfig: 2345 55 25

    echo 开机报时`date` >/tmp/a.txt

    [root@localhost ~]# chmod +x /etc/init.d/ceshijiaoben         #为脚本文件添加执行权限

    [root@localhost ~]# ll /etc/init.d/ceshijiaoben                 #查看脚本文件的权限

    -rwxr-xr-x 1 root root 60 Apr 8 16:40 /etc/init.d/ceshijiaoben

    [root@localhost ~]# chkconfig --add /etc/init.d/ceshijiaoben     #将脚本文件添加到开机启动服务中

    [root@localhost ~]# reboot                                #重启

    Broadcast message from root@har

        (/dev/pts/0) at 16:43 ...

    The system is going down for reboot NOW!

    [root@localhost ~]# Connection closing...Socket close.

    Connection closed by foreign host.

    Disconnected from remote host(52113) at 16:44:28.

    Type `help' to learn how to use Xshell prompt.

    [x:~]$

    Connecting to 10.22.66.132:52113...

    Connection established.

    To escape to local shell, press Ctrl+Alt+].

    Last login: Sun Apr 8 16:42:37 2018 from 10.22.66.1

    [root@localhost ~]# chkconfig --list|grep ceshijiaoben    #检查脚本文件的运行级别

    ceshijiaoben     0:off    1:off    2:on    3:on    4:on    5:on    6:off

    [root@localhost ~]# cat /tmp/a.txt                     #检查脚本文件重定向的文件是否成功

    开机报时Sun Apr 8 16:51:21 CST 2018

     

    博主原创文章,转载请务必注明出处

  • 相关阅读:
    (引)spring学习笔记1.什么是控制反转
    Arduino 各种模块篇 步进电机 step motor 舵机 servo 直流电机 总复习
    Raspberry Pi Wireless Adaptor
    Pyramid 使用总结1
    Arduino 各种模块篇 人体红外感应模块 proximity sensor
    Pyramid 使用总结2
    Webcam Streaming Desktop Recording on Linux for ubuntu or its destros
    Arduino 各种模块篇 步进电机 step motor( 不用库,不用shield, 纯)
    Arduino 各种模块篇 motor shield 电机扩展板(舵机、直流电机、步进电机party)
    转载 stepper motors
  • 原文地址:https://www.cnblogs.com/ssgeek/p/9220637.html
Copyright © 2011-2022 走看看