Apps :: How Do I Run Python Scripts At DSL USBStick Bootup



Hi folks!

I now have DSL 0.8.2 booting up from a PNY 256MB USB 2.0 USBStick/KeyDrive/PenDrive/ThumbDrive (/dev/sda1), including python.uci.

Now, how do I run one, or more, of my own Python scripts, stored on the USB Stick, automatically, at bootup?

I've located Python in /opt/python/bin, and I suspect that there is some command that will allow me to execute/run Python from any other directory path.

In another post, I found the following, which might be related:

export PYTHONPATH=/opt/python/bin
export PATH="$PATH:$PYTHONPATH"

Am I on the right track?  Where (which file) do I modify with these two lines, or whatever else that is needed?

Also, what file needs to be modified so that my Python script(s) are executed automatically at bootup?

BTW, I wasn't able to 'multi-partition' the PNY 256MB USB Stick into sda1 & sda2 (The PNY FAQ webpage said that it wasn't possible).  I probably was just doing something wrong.  I'll leave it for another day.

Thanks for all the informative posts, past & future!

Wasgate

maybe your scripts could be useful 4 other people?
Yep,
What you found will help you get to where you want to be.

e.g.

You want "myfav.py" to run at boottime .

make a script like this..

#!/bin/bash
export PYTHONPATH=/opt/python/bin
export PATH="$PATH:$PYTHONPATH"
python /home/dsl/myfav.py

Save the script under a name like " start_myfav "
Add a line for the start_myfav script to your /opt/bootlocal.sh file .. This will autorun it at boottime
e.g   /home/dsl/start_myfav

You will need to place copies of BOTH myfav.py AND start_myfav
in a path location, like /home/dsl/ , as I did in the scripts ..
If you place them anywhere else, edit your entries accordingly.

Then you need to add both files to your /home/dsl/filetool.lst ,
so your backup picks them up..

home/dsl/myfav.py
home/dsl/start_myfav

Now, create a backup , either thru the dslpanel or the menu.

Then reboot, ... when you reach the boot: prompt
add the line " restore=sda1 "  to your bootup commands ..
( or restore=??  wherever you made your backup write to )

The system will restore the backup, and run the bootlocal.sh ..
The bootlocal.sh will find and execute the start_myfav script ..
The start_myfav will find and execute the myfav.py in a python env.

73
ke4nt

Thanks, ke4nt/Kent, for the thorough reply.

I've had some success, but ran into a problem with the backup.tar.gz creation process.

First though, I want to mention that I decided to keep the 'start_myfav' bash script and my Python script(s) on the keydrive (sda1), so that I wouldn't have to modify filetool.sh for their sake.

Next, even though /dev/sda1 is automatically mounted as /cdrom, I added 'mount -t vfat /dev/sda1 /mnt/sda1' to bootlocal.sh.  The next line after this was '/mnt/sda1/MyPython/start_myfav' to execute the 'start_myfav' bash script (/mnt/sda1/MyPython is where I'm keeping the bash script and Python scripts).

The advantage to keeping the bash script 'start_myfav' and my Python script(s) on the sda1 keydrive, in my mind, is so that I won't have to modify filetool.lst on their behalf (bootlocal.sh is already in the list of backed up file, in filetool.lst).

I then attempted to do a backup (to backup the change to 'bootlocal.sh'), but had a bit of trouble figuring out what to type into the filetool 'Device:' input field.  I finally settled on 'sda1' which eventually created 'backup.tar.gz' on the root of sda1.  So far so good.

I then rebooted, and used 'dsl restore=sda1 mydsl=sda1' at the 'boot:' prompt.

Once booted, I verified that bootlocal.sh executed by checking that /dev/sda1 got mounted to /mnt/sda1, which it had.  However, the line '/mnt/sda1/MyPython/start_myfav' apparently didn't get executed, as my Python script didn't start up.

So, I started tweaking this particular line to try to get it to work.  I'd make a change to bootlocal.sh and then do a backup, prior to rebooting.  I did this once, and for some reason decided to manually delete backup.tar.gz on sda1, just prior to doing another backup, after modifying bootlocal.sh.

Then, the problem cropped up.  I'd attempt to do the backup, using either the DSLPanel or DSLMenu, but it wouldn't create backup.tar.gz on sda1.

Since I was starting to get tired, I decided to call it quits and post this progress report post.  I hope it's written well enough to get the idea of the problem across, as I'm still tired!

I'll return to the problem tomorrow, with a fresh mind.  I'll get it figured out.

Thanks again for the detailed info.

Wasgate

if you boot from /dev/sda1.
then /dev/sda1 is mounted as /cdrom.
dot NOT EVER mount /dev/sda1 again to /mnt/sda1
the problem is that at backup time the filetool.sh tries to find the sda1 in the mtab file. it will find 2 entries for /dev/sda1.
therefore the backup will fail.

if you want your python script to run use:
/cdrom/MyPython/start_myfav
and not
/mnt/sda1/MyPython/start_myfav

Next Page...
original here.