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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With