LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Boot script (https://www.linuxquestions.org/questions/linux-software-2/boot-script-4175468793/)

scarr999 07-07-2013 02:13 PM

Boot script
 
OK I'm new to Linux but know my way around a PC and various languages, however, I cannot figure out how to run something at boot (before user login)

I have tried a few things but nothing quite works so I thought i would ask here

Hardware beagle Bone Black with Debian wheezy

Thanks

P.S. Ideally I would like to run a python script

Steve

yooy 07-07-2013 05:07 PM

There are several boot levels depending on when you want your script to start.

this may help you a bit, as you might forget googling before asking..
http://www.cyberciti.biz/tips/linux-...-boots-up.html

scarr999 07-07-2013 05:24 PM

Thanks yooy,

I did Google first, but Google can be confusing when you are not sure about the subject.

Steve

scarr999 07-07-2013 05:49 PM

OK, I made a script in /etc/init.d/ called mystartup.sh (see below)
then "sudo chmod +x mystartup.sh" (whilst in /etc/init.d/ directory)
ran "sudo upate-rc.d mystartup.sh defaults 100"
Rebooted and nothing :-(

### BEGIN INIT INFO
# Provides: mystartup
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: No comment yet
# Description: No comment yet
### END INIT INFO

#!/bin/bash
echo "something"

evo2 07-07-2013 08:10 PM

Hi,

as far as I can see, what you described should work. Can you confirm that there really is a sybolic link to your script in /etc/rc2.d/?
Eg
Code:

ls -l /etc/rc2.d/*mystartup.sh
I'm assuming you didn't change the default run level. Also, if all your script does is echo a single string then you might miss seeing it during the boot. Pheraps you could make it do something else that is easier for you too see. Eg
Code:

date  > /tmp/mystartup.txt
This just creates a text file containing the date and time it was run. Then after the machine has booted you can look for the existence of the file /tmp/mystartup.txt

Evo2.

jpollard 07-07-2013 09:06 PM

Only thing I see wrong is that the #!/bin/bash line must be first...

scarr999 07-08-2013 03:14 PM

It Works!
 
Thanks guys it now works, I moved #!bin/bash line and did date to file and file was there.

Now if I change the script to run a python script will it launch the script once at boot or for each terminal session I start?

Steve

P.S. Is there anything I should understand about running python scripts from shell scripts?

jpollard 07-08-2013 05:22 PM

If it is in /etc/init.d and specified to be started, only once per boot. It will also be invoked at shutdown.

frankbell 07-08-2013 07:33 PM

Brain skip.

evo2 07-08-2013 08:12 PM

Hi,

Quote:

Originally Posted by scarr999 (Post 4986476)
Now if I change the script to run a python script will it launch the script once at boot or for each terminal session I start?

It will run once with the argument "start" each time runlevels 2-5 are entered and each time with the argument "stop" the system exists those same runlevels. The running of the script is not related to starting terminal sessions.

Evo2.


All times are GMT -5. The time now is 09:00 PM.