Thursday, July 10, 2008

Working startup and shutdown scripts in Eee PC

Info from following URLs:

Info on Linux bash scripting for

Hmm...why the word "Working" in the title? Well, when I first searched the Net for adding boot time scripts to the Eee PC, I was led to those URLs above marked with 'xx'. Debian, and presumably Xandros (the OS in the Eee PC), uses a Sys-V like init system, where scripts are processed at runlevels (0..6,S). Scripts are placed in sets for each runlevel and placed in /etc/rcX.d (where X is 0 to 6, S).

I diligently followed all the instructions but nothing happened at all. Finally, after 2 days, I chanced upon the URLs above marked with '**' that told me that the Asus Eee PC uses fastinit which is a small program to handle all boot up sequences. NONE of the /etc/rc.d files will be processed %-O

The purpose of my searching on boot time scripts was to add timestamp logs for my Eee PC, to track the time used and thereby estimate battery consumption rate. First, I will step through the creation of a simple init script. All bootup scripts are located in /etc/init.d

  1. Press Ctrl-Alt-T to open the terminal console.

  2. Create an empty log file by typing
    "sudo nano /var/log/startup-shutdown.log"

  3. Type a description header if you want. Press Ctrl-O to save and press Ctrl-X to exit.

  4. Set the correct permissions so that the script can write to it.
    Type "sudo chmod 755 startup-shutdown.log"

  5. Type "sudo nano /etc/init.d/startup-shutdown-log" to create the init script.

  6. Type in the following:

    #! /bin/sh
    # /etc/init.d/startup-shutdown-log

    # Some things that run always.
    # Remove the comment below if you wish to run it
    # echo "Hello World!"

    # Carry out specific functions when asked to by the system
    # >> appends output to file
    # > overwrites file with output

    case "$1" in
      echo -e "Startup $(date)" >> /var/log/startup-shutdown.log
      #do nothing
      echo -e "SHUTDOWN $(date) \n" >> /var/log/startup-shutdown.log
      echo "Usage: /etc/init.d/startup-shutdown-log {start|stop}"
      exit 1

    exit 0

  7. Press Ctrl-O to save and press Ctrl-X to exit.

  8. Set the correct permissions to execute it by typing
    "sudo chmod 755 startup-shutdown-log"

Now, to include the script at bootup. Any scripts you wish to start at bootup should be placed in the file /etc/fastservices. The Eee PC fastinit will look in there and parse it line by line. Take note that comments are NOT allowed in this file.

Also, the names of the scripts you place inside MUST be found in /etc/init.d

  1. Press Ctrl-Alt-T to open the terminal console if you have exited the previous one.

  2. Type "sudo nano /etc/fastservices". This will create a new file if it's not there.

  3. One script name per line. Assuming it's a new file, my fastservices will have only one line:


  4. Press Ctrl-O to save and press Ctrl-X to exit.

  5. Now whenever my Eee PC starts, it will run my script.

  6. How about stopping the script or running it at shutdown? You can edit /sbin/ and /sbin/ to look in /etc/fastservices to stop each service inside during shutdown or reboot. Type "sudo nano /sbin/". Here's how would look like after all the editing ( is identical):


    if [ "$1" = "--ask" ]
      zenity --question && sudo $0
      exit $?

    if (test -f "/etc/fastservices")
      for i in $(cat /etc/fastservices)
        /usr/sbin/invoke-rc.d $i stop

    [ `id -u` = "0" ] || echo "Must be root."

    /usr/bin/killall --wait usbstorageapplet

    /bin/kill -USR2 1

  7. When the Eee PC is shutting down, will call your script with the argument 'stop'. What your script does when called with 'stop' depends on what you wrote in the CASE statement. Now, shutdown and startup your Eee PC and see the works. Do note that your script may be run AFTER everything else has been run, so if you open the timestamp log straight after booting up, it may not have been written to yet. To open the log, press Ctrl-Alt-T to open the terminal console and type
    "sudo nano /var/log/startup-shutdown.log".

(^ v ^)

No comments: