Ubuntu18开机执行shell命令

时间:2020-12-01 12:15:17   收藏:0   阅读:12

1.打开shell终端,输入

sudo vi /etc/rc.local

2.在编辑器里面输入自己要启动的脚本

#!/bin/bash

echo "run incar ai program..."

cd /opt/robot

nohup bash autorobot.sh & 2>/dev/null

3.启动脚本示例

#!/bin/bash
  
#ppp connection

errcount=0

while true
do
        if (( $errcount > 10 )); then
                echo "rebooit"
        fi

        echo "errcount is $errcount"

        airobot=$(ps aux | grep airobot | grep -v grep |wc -l)

        echo $airobot

        if [ $airobot -eq 0 ]; then
                sleep 1
                echo "no cold process"
                echo "starting"
                nohup ./airobot &
                errcount=$(( $errcount + 1 ))
        else
                echo "process exsits"
        fi

        sleep 10
done

  

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!