I want to run a script when the system starts. The script is:

gnome-terminal --tab -t "MyPC" -e "sh -c 'nohup firefox & nohup gedit & bash'" --tab -t "MYPC2" -e "sh -c 'ls -al;ls; bash'" > /home/user/gnome

So I copied my script to /etc/init.d and ran update-rc.d boot-up defaults

boot-up is name of my script.

Now, when I restart, the gnome-terminal is not opening (as wriiten in script), though I can see /home/user/gnome file being created which is empty.

I tried other methods like putting it in /etc/rc.local to no avail.

The only way the script runs is when I add it through startup-Applications.

Any idea How to make it work??

I am using Ububutu 12.10

  • systemd will help you :) – Thushi Dec 15 '14 at 10:37
  • Can you please elaborate? – Siddharth Trikha Dec 15 '14 at 10:38
  • Ok...Systemd is a service manager for linux. It is simple and easy to use. You need to have an unit file that executes your script at the startup. You can specify the dependencies if you have any to run your startup program.If you can use systemd in your environment then I can give you information about the sample service to run from systemd. – Thushi Dec 15 '14 at 10:41
  • According to wiki.ubuntu.com/systemd ubuntu's systemd is still very experimental, and works best on 15.04, but it might work ok on 14.10, so I doubt it's going to be much good on 12.04 – PM 2Ring Dec 15 '14 at 10:46
  • systemd is the simplest suite to manage the services. I'm using systemd for almost one year and I didn't faced any problem even for my complex requirements. – Thushi Dec 15 '14 at 10:49

This script will not run correctly at boot time as gnome-terminal, firefox and gedit will expect a X session to be running.

The init.d and/or systemd route is too early in the boot process for your requirements. You'd be better off creating a .desktop file and configuring your system to auto-start this on login.

Create a the file as follows:-

$ gedit ~/.config/autostart/my_stuff.desktop

and add the following:

[Desktop Entry]
Name=My Script

Note that ~/my_script.sh should point to the script you've created. Save it.

Make it executable:

$ chmod o+x ~/.config/autostart/my_stuff.desktop

When you next log in, it should open your terminal, firefox and gedit for you.

  • Yeah I agree with your answer. Upvoted :). But how can you say this won't work from systemd. I'll run my unit file once the x is initialized.I mean i'll add x as my dependency to my unit file to delay it. – Thushi Dec 15 '14 at 11:57
  • I was going to mention that it's pointless starting those programs before X is running, but I got distracted by the systemd v upstart stuff. :) – PM 2Ring Dec 15 '14 at 11:57
  • 2
    @Thushi - X will be initialised as soon as you see the login screen. However, if you're not logged in you won't have an X session for your applications to use and they'll bork. So even waiting for X is still too early to launch your script. – garethTheRed Dec 15 '14 at 12:01
  • The environment I was working is not having the login screen.So I was in that context. Thank you for correcting me. :) – Thushi Dec 15 '14 at 12:02
  • 1
    @garethTheRed - Yeah X will be up before the user is logged in but X may not be the dependency for your unit file.We can identify the suitable service that runs after the login and we can add that dependency.But anyway OP is using 12.04 no need of systemd. I just introduced the alternate way to run the script at the startup :) . – Thushi Dec 15 '14 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.