running my own script during startup

Hi, I am using scientific linux with is a red hat cloning.

I have written a script and I want it to be run during startup before the user log in.

How do I do that?

I know that there is some connection to the run level and the directory /etc/rc.d.

But I don't know how exactly to do it ?

So if someone can explain to me the issue with a little more details.

Lets assume that I have already a script and that it has execution permission, who do I make it run at startup before the user do login?

The exact location can vary, but look for a file under /etc named local.start

You can also do it in a users' crontab, with a line like @reboot /path/to/script.sh

1 Like
  • control runlevel
  • If script is start with S which is start at startup.
  • If script is start with K which is stop at startup.
  • All of rcx.d permissions are 777
# runlevel
N 5
# cd /etc/rc5.d/
# touch 777 Sxxangel
# vi Sxxangel      // paste script
  • paste script to Sxxangel file like below. Script run at background with "cd~"
cd /home/xxxx/yyyyy/
./startwatch.sh
cd ~
cd /home/xxxx/zzzzz/
./startwatch.sh
cd ~ 
1 Like

getrue, thanks a lot.

But since I want to work before the user log in shouldn't it in the rc1.d directory?

And from what I understand from you I should only need to add 'S' to the name of the script and copy it to that directory.

Should I do it manually or there is some command to do it?

One last thing I read that all this issue work with links to the scripts and not the scripts themselves are there, but I could be wrong, so I would love correction.

  • K = stop during startup S = start during startup
#runlevel
N 5
# ls -l /etc/rc5.d/
total 236
lrwxrwxrwx  1 root root 18 Nov 11  2009 K89netplugd -> ../init.d/netplugd 
lrwxrwxrwx  1 root root 19 Nov 11  2009 K90bluetooth -> ../init.d/bluetooth
lrwxrwxrwx  1 root root 18 Nov 11  2009 K94diskdump -> ../init.d/diskdump
lrwxrwxrwx  1 root root 23 Nov 11  2009 K99microcode_ctl -> ../init.d/microcode_ctl
lrwxrwxrwx  1 root root 15 Nov 11  2009 S25netfs -> ../init.d/netfs
lrwxrwxrwx  1 root root 14 Nov 11  2009 S26apmd -> ../init.d/apmd
lrwxrwxrwx  1 root root 16 Nov 11  2009 S28autofs -> ../init.d/autofs
lrwxrwxrwx  1 root root 16 Nov 11  2009 S40smartd -> ../init.d/smartd
lrwxrwxrwx  1 root root 15 Nov 11  2009 S44acpid -> ../init.d/acpid
lrwxrwxrwx  1 root root 11 Nov 11  2009 S99local -> ../rc.local
# 

You have three options.

1- #/etc/rc.local // add line
2- #/etc/rc5.d/ // #touch 777 Sxxangel and edit like above
3- #crontab -e // add this line "@reboot /path/to/shell.script"

That's all from me. :smiley:

1 Like