当前位置:   article > 正文

linux开机自动执行命令或自动启动程序(rc.local)_rc.local 开机自启动sh

rc.local 开机自启动sh

linux开机的最后会执行/etc/rc.local,因此可以在此脚本里面添加shell命令自动执行或者自动启动某个进程。
比如

自动输出信息:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

echo "hello world!"

exit 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

在这里插入图片描述

另一个例子

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

/usr/local/bin/gen-friendlyelec-release   #执行程序
. /etc/friendlyelec-release               #执行程序
if [ ! -f /etc/firstuse ]; then           #-f作用是判断/etc/firstuse是否为一般文件 !作用是取反
    /bin/echo ${BOARD} > /etc/hostname
    /bin/sed -i "s/\(127.0.1.1\s*\).*/\1${BOARD}/g" /etc/hosts
    /bin/hostname ${BOARD}
    /bin/echo "0" > /etc/firstuse
fi

if [ -e /usr/bin/setqtenv ]; then         #-e作用是判断/usr/bin/setqtenv是否存在  
. /usr/bin/setqtenv
/usr/bin/lcd2usb_print "CPU: {{CPU}}" "Mem: {{MEM}}" "IP: {{IP}}" "LoadAvg: {{LOADAVG}}" 2>&1 > /dev/null&
#/opt/QtE-Demo/run.sh&
fi

exit 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

自动执行另一个shell脚本

#!/bin/sh

sh /etc/init.d/S100auto_wifi_link.sh
echo "wifi finish!!"
  • 1
  • 2
  • 3
  • 4
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/401119?site
推荐阅读
相关标签
  

闽ICP备14008679号