Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

start shell script at boot time in linux redhat

Tags:

redirect

linux

I want to run one shell script during booting of my linux server having redhat.

Below are the steps I followed to achieve this

1) I have created script /home/user/script/test.sh

    #!/bin/bash
    echo "xyz" >> output

2) I have made script file as executable using below command

chmod +x /home/user/script/test.sh

3) I have created put test.sh file inside /etc/init.d directory

4) I have made soft link for using below command

 ls -s /etc/init.d/test.sh /etc/rc.d/S15test.sh

5) reboot the server

Another things I have tried is put below line inside /etc/rc.local file

/bin/sh /home/user/script/test.sh

But still I am not able to execute code written inside test.sh file.

like image 217
user3812269 Avatar asked May 22 '15 06:05

user3812269


People also ask

How do I run a shell script on startup?

Test Test Test: Run your test script without cron to make sure it actually works. Make sure you saved your command in cron, use sudo crontab -e. Reboot the server to confirm it all works sudo @reboot.


1 Answers

According to the RedHat documentation RUNNING ADDITIONAL PROGRAMS AT BOOT TIME, you can add commands to the /etc/rc.d/rc.local script.

If you are not seeing anything, try turning on tracing in the rc.local script to see what is happening:

set -x

and you can send the trace to a known log file if you want:

exec 2>/tmp/logfile
like image 141
rghome Avatar answered Oct 18 '22 21:10

rghome