8

I just want to run a very simple command on startup. How can I do that? I've searched google and it has very complicated examples, but what I need is just run this script on startup. How can I do that?

Script

./init.d/opscenter-agent start

3 Answers 3

8

If you want to do this as system startup (as opposed to when you log in to your computer), put the commands you want to run in /etc/rc.local.

See [Ubuntu] Executing a script at startup and shutdown.

1
  • The OP specifically asked for an init.d script, which this is really not. It's a related approach, mostly by virtue of it's being the way we did things 30 odd years ago, and more or less never do now thanks to newer approaches like init.d. (which is in turn being deprecated in favour of systemd's /etc/init).
    – mc0e
    Jun 2, 2015 at 13:33
3

If the script does not need to be run by root, you can do this:

1) Open "Startup Applications Preferences" (Alt + F2 and paste gnome-session-properties and hit Enter),

2) Press "Add" and select your script:

enter image description here

enter image description here


If you are not using a graphical environment, you can put the commands just before the line exit 0 in this file: /etc/rc.local. (To edit it just paste at terminal sudo nano /etc/rc.local.

3
  • Not good since I'm using Putty in order to manage Debian server, no GUI :)
    – sed
    May 6, 2012 at 15:02
  • You can put the commands (or a link to your script) in this file: /etc/rc.local
    – desgua
    May 6, 2012 at 15:10
  • This is an alternative to the init.d script the OP asked for.
    – mc0e
    Jun 2, 2015 at 13:34
1

The /etc/rc.local approach will 'run a very simple command at startup', but it is not an init.d script approach, and is in various ways inferior. (That may not matter, depending on your purpose).

Unlike init.d scripts, rc.local comands don't offer a standard interface to starting and stopping a process, and they don't offer much ability to influence when in the startup process they are run. You can see in the /etc/init.d/rc.local script that this is run after everything else (Required-Start: $all).

If an init.d script really is what you want, then usually just grabbing an existing script, copying it and editing it works fine, though some of the existing scripts have more complexity than you want. Since that's how most init.d scripts start, ubuntu provides /etc/init.d/skeleton for this purpose.

Also worth a look:

  • /etc/init.d/motd is a minimal example that runs something at startup, but with the Required-Start parameter setting when it should happen.
  • /etc/init.d/cron is a simple starting point for a daemon process (give or take the parse_environment function, which you probably don't need).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .