Script at boot

Gerhard Häring gh_pythonlist at gmx.de
Tue Dec 4 13:18:23 EST 2001


On Tue, Dec 04, 2001 at 12:18:01PM -0500, brian.hare at highmark.com wrote:
> I'm not a python programmer (yet), but I am a JavaScript programmer to a
> degree.
> 
> My questions is this:  Can a Python script be made to run at every
> boot/reboot?
> 
> My project is this:  I've got Familiar linux running on an Ipaq handheld
> PC.  I need a script to run every time the device is rebooted.   Is this
> possible with python?   It's kind of the equivalent of putting something in
> startup folder of windoze I suppose....

Just like in other Linuxen, the startup scripts can be found in
/etc/init.d. These are normally shell scripts which can easily invoke a
Python script.

The normal way to proceed is to copy /etc/init.d/skeleton to, say
/etc/init.d/custom and then edit the custom init script to your liking.
But you're not finished, yet. On a SysV style Unix, the symlinks in
/etc/rc[0-6].d determine when the script is actually executed (in single
or multi-user mode or when shutting down). I'm no expert here, so for
more details, I'd recommend to read some docs on the Linux boot process
("man init" or some such).

Here's a sample init script (the file /etc/init.d/custom):

#! /bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
SCRIPT=/root/bin/myscript

case "$1" in
    start)
        echo "Doing my custom initializations."
        $SCRIPT
    ;;
esac

The actual Python script is in /root/bin . I tried a dummy one (Be sure
to make a chmod +x to make it executable).

#!/usr/bin/python
print "My custom script."

Because my iPAQ with Qt Palmtop Environment doesn't have a nice script
to set the symlinks, I'd just set a symlink myself, for example:

ln -s /etc/init.d/custom /etc/rc2.d/S20custom

Btw. I do all such adminstrative operations while being logged in via
ssh. This requires a PPP connection to the host PC. (And knowledge of
via or having another console editor installed).

Low-level operations like watching the boot process (for verifiying your
script actually gets executed, for example) are best done with using
minicom over the serial console.

Details for setting up ssh and minicom and much more valuable
information can be found on the Wiki at http://www.handhelds.org/ They
also have several mailing list with people who know more than me.  There
are also a #handhelds.org and #ipaq IRC channels on
irc.openprojects.net.

Gerhard
-- 
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id 86AB43C0
public key fingerprint: DEC1 1D02 5743 1159 CD20  A4B6 7B22 6575 86AB 43C0
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))




More information about the Python-list mailing list