-   SUSE / openSUSE (
-   -   How to run a command automatically on start up (

TKD 11-02-2005 04:57 PM

How to run a command automatically on start up
Sorry for (what seems to me as), a stupid question - I'm an IT pro but very new to Linux and fairly embarassed about it :)

I'm looking to run a command automatically at startup...

Specifically - ip route add 'ipaddress'/24 'gateway'

How could i do that?
In windows I would have just used the -p switch, is there an eqivalent in Linux?

Continuing from that - how would I launch an application immediately after log-in?

IamSpOOk 11-02-2005 05:11 PM

You can make a permanent route by adding it to /etc/sysconfig/network/routes

acid_kewpie 11-02-2005 05:12 PM

i'd assume there's a better solution to actually do what you want, but to do literally what you're asking, you'd add a line to /etc/rc.local

as for logging on, well that can be a little messy.. what does "log-in" mean? sounds daft, but every time you open a new terminal window in X, you're essentially logging on again... you can so this by adding commands to ~/.bashrc per user, but i don't think this is really what you're after

IamSpOOk 11-02-2005 05:12 PM

If it's an X application, then you can add this to .xinitrc (or equiv for your particular display manager)
You can also add to the profile for your shell - typically ~/.bashrc

scott_R 11-02-2005 05:24 PM

The ridiculously easy way is simply to take that line, preface it with a line above it invoking bash, then drop it into your start scripts directory (varies with distribution)

For instance, the script would be (and this most likely remains true on all distros):

#! /bin/bash
ip route add 'ipaddress'/24 'gateway'

create the file with your favorite editor, then navigate to /etc, and look for something along the lines of rc#.d (or a variation like rc.5, etc.), and copy the file there with the prefix S## (bigger numbers are better, as they start later, allowing more important processes to start first, though you might need a smaller number so it starts before a process that needs it up and running) (as the root user, obviously). use chmod to make sure it's readable/executable ('man chmod' on the command line can guide you), and reboot to test, or start the file manually (/etc/rc'directory'/name of your file.

Sounds complicated, but you can get the idea by looking at the relevant /etc/rc... files and directories and taking your cues from them. Don't be too worried about some of the items in the files themselves, as they are simply shell scripts to ensure that the programs don't start multiple copies or restart if they fail (you can add these things later, but for now they are redundant, as you can manually do the same if you must, and they don't typically fail in this manner).

TKD 11-02-2005 05:54 PM

Thanks guys - perfect. Seems that I learn at least 5 new useful procedures with every thread I read round here.

As for what I meant by 'log-in', sorry about that i'm still with 'windows speak' for the time being. I was refering to starting a session in X. Say if I logged in as 'TKD' i want gaim to auto-launch - whereas i'd want different apps to launch if i logged in as root.
Should I be looking at .xinitrc for this?

acid_kewpie 11-03-2005 04:41 AM

well no you wouldn't, again depends what you're logging in to... gnome and KDE will autosave sessions is you want them to, so that's done at a totally hands-off patronizng gui level :) afaik, .xinitrc is only used when you load X from a console, not when you log into X through a grpahical login maanger. there is ~/.Xsession though.

All times are GMT -5. The time now is 10:41 AM.