How can I run scripts automatically when Ubuntu starts up so I don't have to run them manually after startup?
This question has an open bounty worth +50 reputation from Fabby ending in 5 days.One or more of the answers is exemplary and worthy of an additional bounty. Muru's answer needs a bit of help to climb up the ranks because the other existing answers are outdated. :-) |
|||||
|
|||||
|
Depending on what sort of scripts you need to run.. For services and the like you should use upstart. But for a user script these should be launched as session scripts by gnome! Have a look under System > Preferences > Startup Applications. On a side note if you need some scripts to be run on terminal login you can add them to the .bash_login file in your home directory. For 14.04 and olderA simple command (one which doesn't need to remain running) could use an Upstart job like:
Save this in a |
|||||||||||||||||||||
|
|
One approach is to add an @reboot cron task:
|
|||||||||||||||||||||
|
|
How about adding the command to
|
|||||||||||||||||||||
|
|
There are different ways to automatically run commands:
|
|||||||||||||
|
For 15.04 and later:To run a (short-lived)1 command at startup using systemd, you can use a systemd unit of type
Then run:
This is not necessary, since Essentially, this is just converting a typical Upstart job to a systemd one (see Systemd for Upstart users). Relevant: For user sessions, you can create the systemd unit in
1As opposed to long-lived daemons. |
|||||||||
|
Sample example for Putting following
Here Sample example of
Result:
Hence, You can run your desired shell script at startup! |
|||
|
|
|
For simple things you can add a command in System->Preferences->Sessions pointing to the location of your script. Alternatively you can add it to /etc/init.d/rc.local or make an upstart job if it's a more low level stuff. Take a look at https://help.ubuntu.com/community/UbuntuBootupHowto for more info |
|||
|
|
|
You should use upstart for this. Upstart is used for Ubuntu processes that are automatically started. It is an enhanced solution like the old System-V init.d scripts. It also allows you to put in prerequisites to the start of your script (i.e. do you need the network running? etc.) |
|||
|
|
|
|
|
There are many different ways to add cronjobs, but the core of the highly voted answer and your answer is still the
@reboot.
– muru
yesterday
|
||
|
|
Alternate methods for adding crontabs should be posted to askubuntu.com/q/2368/158442, which is explicitly about adding Cron jobs.
– muru
yesterday
|
||
|
|
I beg to differ. The core of the answer in question utilizes
crontab -e which some consider one of the black arts due to a vim-like interface. On the other hand this answer might appeal to those whose brains are wired a certain way. We are not all cast from the same mold. Then again this answer already has one down vote so we'll let democracy take her course.
– WinEunuuchs2Unix
yesterday
|
||
|
|
|||
|
|
@muru Yes probably because you taught me and I learned to change editor to something like nano or a couple of other CLI's. But I'm in the gedit camp. Besides
crontab -e brings up memories of asterisks ("*") for minutes, hours, etc. that I've always found I need to google instructions for. I still find using /etc/cron.d and /etc/cron.daily my go to choice. Especially since it mirrors /etc/udev/rules.d and /etc/systemd/system-sleep methods. It just seems like a nice fit.
– WinEunuuchs2Unix
yesterday
|
protected by Community♦ Jan 14 '15 at 19:17
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?