Exercise: Create your own script for your default run-level



Example Script

#!/bin/sh
# Startup script for myprog
#

prog="myprog"
XCLOCK=/usr/X11R6/bin/xclock

[ -f $XCLOCK ] || exit 0

start() {
    echo -n $"Starting $prog: "
         $XCLOCK -display ponto:0.0 &
    echo "Hello Patty"
    RETVAL=$?
    echo
    return $RETVAL
}

stop() {
   echo -n $"Stopping $prog: "
   kill `ps -ef | grep xclock | grep -v grep | awk '{print $2}'`
   echo "Goodbye Patty"
   RETVAL=$?
   echo
   return $RETVAL
}

case "$1" in
        start)
            start
            ;;

        stop)
            stop
            ;;
        *)
            echo $"Usage: $0 {start|stop}"
            exit 1

esac
exit 0


Make your script executable:

# chmod +x myprog
Test your script from /etc/rc.d/init.d:
# ./myprog start
# ./myprog stop
Now create symbolic links in /etc/rc.d/rc4.d to start your script
# cd /etc/rc.d/rc4.d
# ln -s ../init.d/myprog S99myprog
In order to see your program's messages you must be able to view the console.
The clock should appear on your X desktop.
# tail -f /var/log/messages
Did you see your program get exectued when you changed run-levels?

Examine the /etc/inittab script and find the line which executes rc.sysinit.

Write it down:____________________________________________________
Explain each of the 4 fields.
 
 
 
 

To find the current and previous run-level:

# runlevel
To change to run-level 4:
# telinit 4
or
# init 4