how to autorun a shell script after boot - OpenWRT

2.5k Views Asked by At

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?

1

There are 1 best solutions below

8
TkrA On

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.