简体   繁体   中英

how to autorun a shell script after boot - OpenWRT

i just got interested in OpenWRT and want to try somethings.

i'm trying to run a script right after my OpenWRT boots. here is my script file

customchain.sh

#!/bin/sh /etc/rc.common

START=99

start(){
[my custom chains]
}

i've placed this script file at /etc/init.d

i wonder why this won't work. if i check at /etc/rc.d , i can see S99customchain.sh ->../init.d/customchain.sh

when i manually restart script file at root directory with /etc/init.d/customchain.sh i can see it applies well when i check via iptables -L

but as i said, this won't automatically starts when i (re)boot my OpenWRT system.

authority is already given by using +x

i've already tried using /etc/init.d/customchain enable and still doesn't work.

also i already checked similar question at here, and it doesn't have any answers.

what should i do?

1st approach: Add commands to /etc/rc.local

vi /etc/rc.local

inside rc.local:

# Description of the script
#!/bin/sh
/path/to/my/script.sh || exit 1   # comments
exit 0

2nd approach: edit your crontab

crontab -e    

add this line:

@reboot /path/to/script.sh   

The script will run when the computer starts up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM