在OpenWrt中指定自定义脚本开机运行(开机自启 自动启动)

注意:不要使用/etc/rc.local文件,就算你加上了+x的执行权限,它也不运行,不知道怎么回事
要用下面的方法,以我自己需要启动的tcpdump为例

1. vi /etc/init.d/runTcpdump
在里面编辑上你自己需要的代码

#!/bin/sh /etc/rc.common
#/init.d/runTcpdump

START=99

start(){
    /usr/sbin/tcpdump -ni br-lan not port 22 -s 0  -w  /mnt/sda3/tcpdump/net.cap > /dev/null 2>&1 &
    echo "tcpdump is startd"
}

stop()
{
    killall tcpdump
    echo "tcpdump is stopd"
}

注意里面的 > /dev/null 2>&1 & 这个东西哦,有很大的学问,不能省了

2. chmod +x /etc/init.d/runTcpdump

3. 设置自动启动 ln -s /etc/init.d/runTcpdump /etc/rc.d/S99runTcpdump 或者 service runTcpdump enable(推荐这个简单)

然后重启,测试下吧
重启后,输入命令 ps -efww | grep tcpdump ,如果有相应的进程,就OK了



发表评论

您的电子邮箱地址不会被公开。

52 − 49 =