How to run scripts on Centos startup?

Asked

Viewed 3,751 times

0

Good afternoon, how do I run a script in Centos 6.5?

I’m running into

 /etc/rc.local 

 /etc/rc.d/rc.local

and is not loading the commands:

sh /etc/init.d/script

the command works outside the script.

  • It would be in the system startup!

  • André, was that comment an answer? In this case it would be interesting to put it in the field of answers and share it with others.

  • Managed to solve your problem?

2 answers

1


you have the commands set in the file "script"

if that is it try to give full permission to the file and turn it into executable.

chmod +777 /etc/init. d/script

chmod +x /etc/init. d/script

1

/etc/rc.local or /etc/rc.d/rc.local are no longer executed due to changes in Centos.

To keep using them, you have to keep /etc/rc.d/rc.local as executable:

chmod +x /etc/rc.d/rc.local

Debug

To debug the problem, it would be a good idea to redirect the script output (/etc/init.d/script > /var/log/seu_log) to be sure if the script is running or not.

Example:

# touch > /root/meu_script.sh
# touch > /var/log/meu_log && chmod 777 /var/log/meu_log

Save the content:

#!/bin/bash
echo 'Nossa! Estou vivo!'

Give permission:

chmod +x /root/meu_script.sh

And schedule your boot run for:

/etc/init.d/script > /var/log/meu_log

After booting, see if the file /var/log/meu_log is empty or written. If empty, obviously the script did not run on boot.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.