Is there any way to make/run a bash script on reboot (like in Debian/Ubuntu for instance, since thats what my 2 boxes at home have)
Also, any recommended guides for doing cron jobs? I'm completely new to them (but they will be of great use)
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
On Ubuntu/Debian/Centos you can set up a cron job to run @reboot. This runs once at system startup. Use crontab -e to edit the crontab and add a line like the example below e.g.
There are lots of resources for cron if you look for them. This site has several good examples.
Another typical way to start something at boot on many *nix platforms is (or was, I think this may be starting to loose favor -- see alternatives) to put scripts in a directory which, depending on the particular OS/distribution, might be something like
/etc/rc/rc3.d, or the like (different distributions use different "run levels", which is where the number comes from -- see the link below). Frequently, these are also symlinked either into or at files from
/etc/init.d, for more easy execution by hand, and they take a "start" and/or "stop" argument in most *nix platforms, and also "status", "restart", etc. on many linux platforms. On such systems, these are generally executed by
inittab -- see SysV init scripts. On *BSD systems, there's a different style of a similar concept, and, as linked above, there are a bunch of variations.
In the above style, scripts in, e.g.,
/etc/rc2.d (for a system with a default runlevel of 2) typically start with either the letter
K, and then a two digit number. The scripts that start with S are run in lexicographic order (which translates, generally, into numeric order) when booting up, into level 2, with an argument of "start". When shutting down, the scripts prefixed with K are similarly run, with an argument of "stop".
The files in
/etc/init.d (or sometimes
/etc/rc/init.d, or other variations) are named without the S and K prefixes, or the numeric numbers. Typically, the files in the various /etc/rc?.d directories symlink to the real files, often referenced via the relative path prefix
Various utilities exist on various systems to manage these, as well, turning things on and off, etc. On IRIX (since IRIX 4, at least, if my memory serves), it used to be a tool called
chkconfig, which wouldn't manipulate the links, but which would be checked by the scripts to see if they should run or not. I think IRIX was the first OS to have something like this. Later, in some version of RedHat that I used to have, there was a tool by the same name, but it behaved a bit differently, actually managing the symlinks -- see
chkconfig(8) for what I think is likely the same (or very similar) version as I used then.
On an Ubuntu 9.04 system I have access to, it looks like
update-rc.d is the script to run.
If you're on a system that uses inittab, you can also add things directly there -- which can be especially useful for things that you want to run not just once at boot, but to have actively monitored (by
respawn if they ever crash or terminate. See the output of
man inittab (if you have it) on your system for additional information. And/or
man init, etc. There are lots of different flavors, and I'm not (currently) terribly familiar with either Debian or Ubuntu, so I'm not sure exactly what to point you at, but hopefully this gives you some starting points.
the @reboot section in crontob is new to me, but also seems like it might be a useful option -- though I would suggest init scripts as being preferable for many things. But see
man 5 crontab for much more info on what you can put in your cron configuration, and how it can be told to run things, and when (including, assuming a Vixie/ISC version of cron [see cron history] with
I hope that's helpful.