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

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

在这里插入图片描述

另一个例子

#!/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

自动执行另一个shell脚本

#!/bin/sh

sh /etc/init.d/S100auto_wifi_link.sh
echo "wifi finish!!"
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

【ql君】qlexcel

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值