LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   RedHat: Getting my script to run after I reboot (https://www.linuxquestions.org/questions/programming-9/redhat-getting-my-script-to-run-after-i-reboot-467531/)

eur0dad 07-25-2006 01:47 PM

RedHat: Getting my script to run after I reboot
 
Hello! I'm trying to get a script to run after reboot, and I have previously gotten advice to place it in the /etc/profile.d/, which turned out to be a horrid idea (almost broke my system). All I'm trying to do with my script is use "apt-get remove" on a bunch of patches. I also heard soemthing about putting it into /etc/rc3.d/, but nothing ever happens when I throw it in there.

Any help?

burninGpi 07-25-2006 02:17 PM

try putting it in /etc/init.d

kilgoretrout 07-25-2006 02:22 PM

You can try running the script from /etc/rc.d/rc.local. That's the last init script to run. Is this something you want to run every time you reboot or just a one shot deal? It's not clear why you would want to remove patches on every reboot. There may be simpler solutions to your problem.

eur0dad 07-25-2006 02:46 PM

Yeah, sorry i forgot to mention, but I will be running it just once.

eur0dad 07-25-2006 02:48 PM

Oh, and what is meant by "running it from /etc/rc.d/rc.local"? Can I just throw it in there and it'll startup after reboot? I'm trying to automate this process in a script, so the "simpler" the task, the better.

kilgoretrout 07-25-2006 06:03 PM

rc.local isn't really for that kind of task; it's meant for recurring commands that you want run every time you boot up. Why don't you just boot up, login and run whatever commands you want? If you have a script that you want run, put it in your home directory, boot up, login and run:

$ su
<enter root password>
# chmod +x <script_name>
# ./<script_name>

The chmod command makes the script executable if it's not already. The "./<script_name>" is the syntax for running the a script in your current working directory which should be your home directory after you boot up, i.e. where I told you to put the script.

billymayday 07-25-2006 06:53 PM

A simple solution is to add a line to crontab

@reboot /path/to/my/script.sh

Beats mucking around with init files for simple tasks

burninGpi 07-25-2006 08:15 PM

Quote:

Originally Posted by eur0dad
Yeah, sorry i forgot to mention, but I will be running it just once.

If you are only going to run it once, then why don't you just reboot and run it manually?

eur0dad 07-25-2006 09:26 PM

Because a script (literally run on thousands of computers) is going to generate THAT script, will need it to run once after reboot and then remove itself. I'm not down for running it manually that many times...

billymayday 07-25-2006 09:39 PM

What if you did something in a script like



#cp /etc/rc.d/rc.local /etc/rc.d/rc.local.save
#echo "/path/to/once/off/script.sh" >> /etc/rc.d/rc.local

At the end of /path/to/once/off/script.sh, have a line like

#mv -f /etc/rc.d/rc.local.sav /etc/rc.d/rc.local

I haven't tried it, but sounds a bit like what you want.

How do you plan to make the initial change to thousands of machines anyway?

eur0dad 07-26-2006 08:27 AM

The user of those machines will be running the script on their own, but for them to do anything but running that initial script is more than what should be required.

I'll give your method a try later, it was something similar to what I was doing yesterday, but I was pasting the code into the wrong file.

eur0dad 07-26-2006 08:48 AM

Hrmm... I put a simple "echo Hi!" in the rc.local file for testing, and nothing got printed when I rebooted.

kilgoretrout 07-26-2006 11:11 AM

Try adding this line to rc.local:

echo Hi! > /home/<username>/hi.txt

On reboot, you will get a text file in your home directory named "hi.txt" with the words "Hi!" in it.

If you have to admin literally thousands of machines, I'd suggest that you obtain the services of a competent linux sysadmin. No offense, but this is not the kind of task that should be undertaken by someone that doesn't understand what rc.local is all about. A rollout of that size by someone inexperienced is a blueprint for disaster IMHO.

eur0dad 07-26-2006 11:26 AM

None taken. I'll try to look for an alternative route or ask one of the guys here to revise this after I'm done with it. Thanks for the advice and warning.


All times are GMT -5. The time now is 12:33 AM.