Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (3) </ 1 [2] 3 >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: How Do I Run Python Scripts At DSL USBStick Bootup, DSL 0.8.2 & Python.uci & USB Stick< Next Oldest | Next Newest >
wasgate Offline





Group: Members
Posts: 7
Joined: Nov. 2003
Posted: Oct. 20 2004,13:54 QUOTE

Thanks, henk1955, for the info.  I was wondering whether double mounting sda1 was a bad thing.  Now I know.

So, now that I've got my backup.tar.gz problem sorted out, I've gotten back to figuring out why my Python script isn't being run automatically at USBStick bootup.

start_myfav will execute if I manually run it from a BASH command prompt!

Here are the contents of the 3 applicable files:



bootlocal.sh ==================================
#!/bin/bash
# put other system startup command here
/cdrom/MyPython/start_myfav                      <-- This line isn't executing!!!
===========================================
When I had the 'mount -t vfat /dev/sda1 /mnt/sda1' line in, it was being executed okay.


start_myfav ==================================
#!/bin/bash
export PYTHONPATH=/opt/python/bin
export PATH="$PATH:$PYTHONPATH"
python /cdrom/MyPython/myfav.py
==========================================
This script runs just fine if I manually execute it.


myfav.py ===============================
#!/usr/bin/env python
print '\n\n'
print 'Hello World!!!'
print '\n\n'
========================================
This is the sample/test Python script, FWIW.

The line '/cdrom/MyPython/start_myfav' in bootlocal.sh is NOT being executed, but will execute if I manually execute it at a BASH command prompt!  Here's the output for when I manually execute start_myfav:

==========================
root@box:~# cd /opt
root@box:/opt# more bootlocal.sh
#!/bin/bash
# put other system startup command here
/cdrom/MyPython/start_myfav
root@box:/opt# /cdrom/MyPython/start_myfav



Hello World!!!



===========================================


So, the question is, why won't the above bootlocal.sh execute start_myfav?

Does anyone see the problem?

Thanks very much.

Wasgate
Back to top
Profile PM 
ke4nt1 Offline





Group: Members
Posts: 2329
Joined: Oct. 2003
Posted: Oct. 20 2004,14:48 QUOTE

Make sure the file start_myfav is executable by everyone..
as root user in shell  > " chmod 777 start_myfav "

Also, try changing the line in your bootlocal.sh from

/cdrom/MyPython/start_myfav

to

exec /cdrom/MyPython/start_myfav

Let us know..

73
ke4nt
Back to top
Profile PM 
roberts Offline





Group: Members
Posts: 4983
Joined: Oct. 2003
Posted: Oct. 20 2004,17:18 QUOTE

First a comment. It has been posted many times that it is not a good idea to use the flash device as a real hard drive. But when I implemented the ability to save backups on the same partition of the flash, then this opens up the capability for someone to use the flash device in a hybrid way such as this approach. However, this has nothing to do with your "problem". Also Python has nothing to do with the "problem".

I believe the script is working. The issues are several. It has to do with the location of the executing script and the supporting environment at that time.

Where were you expecting the output "Hello World" to appear? If you boot your system with dsl 2 restore=sda1 you will see your script output. But a normal boot, boots directly into X. If you exit the window manager you should see your output. Your script would need a controlling rxvt window to display in. But then you have another issue, as X is not started to even have an rxvt window at the time bootlocal.sh is running.

Now, if your Python scripts are to do only "root" non-X tasks then your approach is OK, my comment still applies.

One thing to keep in mind is the various "autoexec.bat" locations in DSL.

System command(s) (root), implies non X use /opt/bootlocal.sh
User commands non X use /home/dsl/.bash_profile
User commands X based use /home/dsl/.xinitrc

The final answer for you, the Python programmer, lies in which type of command/program you will be writing.

You have the wrapper concept working fine. Now it is the location depending on the program's operating envirnoment requirements.
Back to top
Profile PM WEB 
wasgate Offline





Group: Members
Posts: 7
Joined: Nov. 2003
Posted: Oct. 20 2004,23:32 QUOTE

Eureka!!!  I finally got it to work.

First thing:  roberts' comments about USB Stick usage made me rethink, so I moved my bash and python scripts from the USB Stick (sda1, aka /cdrom) to /home/dsl, at least for the time being.  Thanks, roberts!

Second thing:  ke4nt's comments about permissions and ownership caused me to watch/fix the ownership/permissions closely.  Thanks, ke4nt/Kent!

I must admit that I'm still a bit confused with permissions, groups and ownership, because I've noticed that moving/copying files around, as well as editing files, will change these, on occasion.  I need to do more reading on the subject, and get a handle on it.

The 'Bottom Line' is that /opt/bootlocal.sh was:
-rw-rw-r--    1 dsl      staff          74 Oct 20 13:23 bootlocal.sh

When I changed it to:
-rwx------    1 dsl      staff          74 Oct 20 13:23 bootlocal.sh

The whole process worked!


I don't know if/how bootlocal.sh's permissions got changed.  I almost never do any chmod cmds, so if it was changed, it wasn't me (intentionally, at least :)  I'll have to reinstall DSL on my USB Stick and then check /opt/bootlocal.sh to find out (unless someone out there can look at theirs and tell us).

Also, the bash script, /home/dsl/start_myfav (that sets the Python path env stuff) needs to be executable.  The Python script, myfav.py, doesn't, however (for the edification of the other newbies out there!).

The interesting thing, which roberts mentioned, was that my python script ran before the windows manager started up (the tux icon was in the top left corner of the screen).  Once my python script finished, it continued on into the desktop environment.  After DSL init'd into runlevel 5, and after /cdrom/backup.tar.gz is restored, the Python script executed.

Also, there's a chance I had the python script running earlier, but just didn't notice it during the boot process (my 'Hello World' python script was awefully quick).  I'm glad I changed my test python script to one that runs longer than the old 'Hello World' script:

Here's what I ended up with, FWIW:

   import time
   print '\n\n'
   print 'Hello World!!!'
   print '\n\n'
   time.sleep(5)

BTW, this is a handy method of putting a delay in the boot/initialization (dmesg?) 'flood' that occurs!!!  Like I said earlier, this Python script was executed just after the init to runlevel 5 and the backup.tar.gz restore from /cdrom (sda1, the USB Stick).

I was really wanting my script to run in a window on the desktop, but I'll save that for some other time.

Thanks very, very much, gang!  You guys definitely know your stuff!

73 es tnx agn
Wasgate
Back to top
Profile PM 
ke4nt1 Offline





Group: Members
Posts: 2329
Joined: Oct. 2003
Posted: Oct. 21 2004,01:20 QUOTE

Good Work !

If you would like to try to get the program running in a shell on the desktop,
try placing your commands to execute "start_myfav" in your /home/dsl/.xinitrc
file, instead of your /opt/bootlocal.sh..

Look inside the .xinitrc, and you'll see what going on in there.
The only rule is to make sure "fluxbox" is the LAST line in there.

To add an "open shell" command to your "start_myfav" , look in your
/home/dsl/.fluxbox/menu file..
There are many examples of rxvt being opened, and programs executed
with the -e switch. You may want to lengthen your sleep time, as the
shell will close after the script has completed its execution..

One bonus is that your /home/dsl/.xinitrc should already be in your filetool.lst !

73
ke4nt
Back to top
Profile PM 
10 replies since Oct. 19 2004,14:53 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (3) </ 1 [2] 3 >/
reply to topic new topic new poll
Quick Reply: How Do I Run Python Scripts At DSL USBStick Bootup

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code