LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Running a program on startup (https://www.linuxquestions.org/questions/linux-newbie-8/running-a-program-on-startup-896410/)

Rawful 08-09-2011 02:02 PM

Running a program on startup
 
I have a program I have made, and I would like it to run as soon as the system is finished booting. I am using Ubuntu Mini Remix to recreate a LiveCD/USB stick. After booting, it drops me to a command line where I can enter "sudo qct" and it will run my program (which is called qct, and it has to be run as root).

I want this to be automated. Instead of going to a command line, I want it to run the program itself at that point. How would I go about doing this? I have read many tutorials about scripting but I cannot seem to get it to work.

corp769 08-09-2011 02:09 PM

Hello,

Click on System, Preferences, Sessions, and from there, select the "Startup Programs" tab, and you can add your program to be ran on boot.

Cheers,

Josh

Rawful 08-09-2011 02:11 PM

This distro is command-line only, no GNOME or Unity.

corp769 08-09-2011 02:34 PM

Ahh ok, that explains it :p

Does your distro contain the /etc/rc.d/init.d/ directory? It should, but I have never used your distro.... You could always move your script into that directory, then create links to your runlevel directories, such as /etc/rc.d/rc5.d/ and so forth. Or you could just move the script to /etc/rc.d/rc.local.

Cheers,

Josh

Rawful 08-09-2011 03:08 PM

There is:

/etc/init.d/
/etc/rc0.d/
/etc/rc1.d/
/etc/rc2.d/
/etc/rc3.d/
/etc/rc4.d/
/etc/rc5.d/
/etc/rd6.d/
/etc/rdS.d/

there is a rc.local file in /etc/


The script I am trying to run is this:
Code:

#!/bin/bash

qct

It needs to be run as root for the program to function.

corp769 08-09-2011 03:13 PM

Well in order to run it as root, you will have to manually enter your root password. Since you said your distro is command line only, you could place your script name within rc.local and go from there.

Rawful 08-09-2011 03:21 PM

So I would add a line containing "/etc/rc2.d/qctrun.sh" to rc.local?

corp769 08-09-2011 03:23 PM

You can place your script anywhere, just make sure that your script is chmod'd to execute.
Code:

(in rc.local)
/path/to/script/qctrun.sh

Not sure how exactly it will work on your system, but with some tweaking, you can definitely figure it out.

Cheers,

Josh

tredegar 08-09-2011 03:24 PM

Just put /path/to/qct into /etc/rc.local before the final line exit 0 and it will be run as root after everything else has booted up. You'll have to adjust the path to your command, don't take "/path/to/" literally. Example:
Code:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
/home/rawful/qct
exit 0

You can add error checking as you see fit.

Try it out. See if it works.

corp769 08-09-2011 03:28 PM

Quote:

Originally Posted by tredegar (Post 4438099)
Just put /path/to/qct into /etc/rc.local before the final line exit 0 and it will be run as root after everything else has booted up. You'll have to adjust the path to your command, don't take "/path/to/" literally. Example:
Code:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
/home/rawful/qct
exit 0

You can add error checking as you see fit.

Try it out. See if it works.

Beat you to it :p

Rawful 08-09-2011 03:35 PM

Greatly appreciate the assistance, guys. Trying it out now to see if I can get it working :p

Rawful 08-09-2011 03:55 PM

Now it doesn't even boot as far as the command line. It sits at the ubuntu loading screen endlessly filling the same dots with orange and then white :(

It is probably trying to do what I told it to do, but I cannot see.


All times are GMT -5. The time now is 04:50 PM.