Startup Scripts

From DD-WRT Wiki

Revision as of 03:43, 25 May 2005 by Sveasoft (Talk | contribs)
Jump to: navigation, search

You are here: Main Page/DD-WRT Docu (EN)/Telnet/SSH and the Command Line/Startup Scripts



Sometimes you install things and want them to load on startup. Writting startup scripts is the way to go!

Web Interface Method


-know how to access the Web Interface
-know a sequence of commands you'd like to run every startup
-it's best if you've tested your commands at the command line to ensure accuracy


From the Web Interface
-Click on the Administration tab
-Click on the Diagnostics subtab
-Click on the cmd button
-Type the commands you wish to run every startup into the Commands: dialog box (place each command on a newline using the enter key)
-Click the Save Startup button at the bottom of the page (you may need to scroll).

How it Works

What this does is save your string of commands to the rc_startup variable in flash memory (also known as an nvram variable). Since flash memory doesn't get erased on startup, your "startup script" will remain with every boot and will always execute.

NVRAM Method


-Knowledge of Telnet/SSH and the Command Line
-know a command or sequence of commands you'd like to run every startup
-it's best if you've tested your commands to ensure accuracy


Telnet/SSH into your router and issue the following

~ # nvram set rc_startup="
> <command 1>
> <command 2>
> <command n>
~ # "
~ # nvram commit

How it Works

When you issue the first command you'll notice the prompt change to a ">" From here on every line you type is added to the rc_startup variable. You are still technically typing on the same command line, even though you are using multiple lines When you type the final " and hit [Enter] you'll see the prompt change back and your first command has been executed. That is, your script has been added to the variable rc_startup.

At this point you can check the contents of rc_startup by issuing the command:

~ # nvram get rc_startup

When you give the command nvram commit the rc_startup variable is saved in flash memory and will remain when you reboot.

Shell Script Method (Unfinished)

AFTER WRITING THIS WIKI I found that this method DOES NOT WORK Only 1 of the startup scripts runs. I attribute the failure this The last step This can be solved by writing a script that launches all of the other scripts and setting that to load on rc_starup but I'm not sure how to reliably write such a script. The *.startup method does not, however, work. If someone can repair this, please help.

I assume this is because the shell will only take the first match from *.startup ie a.startup or whatever it picks first (this is not always alphabetical). As you say, the correct way to do this is to create a shell script that calls other shell scripts as required.

Simple nvram scripts are fine for short scripts, but if you'd like to do a lot, or if you'd like to easily manage your startup programs, the best method is through using shell scripts.

Shell scripts make it easier to write long scripts that wget files from the internet, or ipkg -d ram install, copy pre made configuration files from the flash partion, etc, etc before finally running your program, and do so on every startup.

This means you don't need to save so much stuff in router flash space (rather limited) but can fill up the much more prevalent ram without having to install and configure your program on every reboot.

And, since every program gets it's own script, removing a program from the next boot is as easy as deleting, moving, or renaming it's startup script file.


-Knowledge of Telnet/SSH and the Command Line
-know a command or sequence of commands you'd like to run every startup
-it's best if you've tested your commands to ensure accuracy
-Have SCP or another working method to copy files to/from the router
-you have jffs initialized and working

Windows users
-TextPad or Win32Pad
(or other *nix friendly text editor. DO NOT USE NOTEPAD)


Write the Shell Script

Write a shell script for each program you would like to run on startup.
your script should be a *.startup file

Shell scripts should look like this:

<command 1>
<command 2>
<command 3>
killall <command n program name>
<command n>

Because of something in the linux system, your shell script could end up being run periodically, and not just at boot (cron maybe??). I'm not a linux user, so I'm not entirely sure why. However, this does mean that you'll need to ensure that only 1 copy of your program is ever run at a time. The killall command ensures that <command n> isn't running more than once simultaneously. This assumes that all commands in the script above <command n> exit immediately after executing (such as cp, wget, or iptables.)

Ex a script: kismet_server.startup

# Make the /tmp/usr/bin folder and move there
mkdir /tmp/usr
mkdir /tmp/usr/bin
cd /tmp/usr/bin

#copy the executable file off my home webserver

#kill an open copies of kismet_server
killall -q kismet_server

#execute kismet_server using /jffs/etc/kismet.conf as the configuration file.
/tmp/usr/bin/kismet_server -n -f /jffs/etc/kismet.conf

Save the Script

Save the script on the router in the /jffs/etc/config directory. You may need to create this directory. Do so either in winscp or using the mkdir command.

Make the Script Executable

Making your script executable means changing the file rights to "700" Do this through winscp or with the command

~ # chmod 700 /jffs/etc/config/<scriptname>.startup

Tell your scripts to load on startup

AFAIK, you should be able to reboot the router at this point and everything should be ok. Something is supposed to launch these scripts at router boot. This has not been the case for me and I've found solice in setting an rc_startup script that launch any/all scripts found in the /jffs/etc/config directory.

Do so with the following commands

~ # nvram set rc_startup="sh /jffs/etc/config/*.startup"
~ # nvram commit

For additional startup scripts, ommit this setup (4.3.4)

How it Works

The command sh /jffs/etc/config/*.startup will execute every script ending in .startup found in the /jffs/etc/config directory. By setting this as the rc_startup value, your *.startup scripts will load every time the router boots.

Shell scripts are much like Windows/Dos batch (*.bat) files. Every line is a new command and execution occurs exactly as if each line was typed seperately into the command line.

SAMBA method

The drawback of jffs is the fact it doesn't work on some firmwares and it is rather small. If you have a samba or windows server running on your LAN you could use the fabulous 'sambashare' option. This adds a vast amount of writable storage to your router, and it is possible to set an automatic startup script when the samba share mounts on boot. You can find the samba share options in the web interface under administration. If you set the startup script option to the actual script run after mounting will be /tmp/smbshare/

See also the Samba Filesystem for details.

You are here: Main Page/DD-WRT Docu (EN)/Telnet/SSH and the Command Line/Startup Scripts