linux 开机自启脚本

1.vi /home/dpf/mqtt.sh

#!/bin/sh
/home/dpf/Desktop/Udp_Single_Async_Mqtt_yuan/hwjc_udp_receive_mqtt &

2.系统脚本可以放置在/etc/rc.d/init.d 中并建立/etc/rc.d/rc?.d 链接,也可以直接放置在/etc/rc.d/rc.local 中。
init.d 脚本包含完整的 start,stop,status,reload 等参数,是标准做法,推荐使用。
为特定用户使用的程序(如有的用户需要使用中文输入法而有的不需要)放置在~/中的 bash 启动脚本中。
========================================================================
设置系统自动启动
在/etc/init.d/下创建 smsafe 文件
内容:
#!/bin/bash
# chkconfig: 35 95 1
# description: script to start/stop smsafe
case $1 in
start)
sh /home/dpf/mqtt.sh
;;
stop)
sh /home/dpf/mqtt.sh
;;
*)
echo "Usage: $0 (start|stop)"
;;
esac
更改权限
# chmod 775 smsafe
加入自动启动
# chkconfig –add smsafe
查看自动启动设置
# chkconfig –list smsafe
smsafe 0:off 1:off 2:off 3:on 4:off 5:on 6:off
以后可以用以下命令启动和停止脚本
# service smsafe start 启动
# service smsafe stop 停止

posted @ 2017-11-24 18:46  丁培飞  阅读(355)  评论(0编辑  收藏  举报