LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-25-2006, 01:47 PM   #1
eur0dad
Member
 
Registered: Jul 2006
Posts: 57

Rep: Reputation: 15
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?
 
Old 07-25-2006, 02:17 PM   #2
burninGpi
Member
 
Registered: Mar 2006
Location: Fort McMurray, Canada
Distribution: Gentoo ~amd64
Posts: 163

Rep: Reputation: 30
try putting it in /etc/init.d
 
Old 07-25-2006, 02:22 PM   #3
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,299

Rep: Reputation: 138Reputation: 138
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.
 
Old 07-25-2006, 02:46 PM   #4
eur0dad
Member
 
Registered: Jul 2006
Posts: 57

Original Poster
Rep: Reputation: 15
Yeah, sorry i forgot to mention, but I will be running it just once.

Last edited by eur0dad; 07-25-2006 at 02:59 PM.
 
Old 07-25-2006, 02:48 PM   #5
eur0dad
Member
 
Registered: Jul 2006
Posts: 57

Original Poster
Rep: Reputation: 15
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.
 
Old 07-25-2006, 06:03 PM   #6
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,299

Rep: Reputation: 138Reputation: 138
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.
 
Old 07-25-2006, 06:53 PM   #7
billymayday
Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
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
 
Old 07-25-2006, 08:15 PM   #8
burninGpi
Member
 
Registered: Mar 2006
Location: Fort McMurray, Canada
Distribution: Gentoo ~amd64
Posts: 163

Rep: Reputation: 30
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?
 
Old 07-25-2006, 09:26 PM   #9
eur0dad
Member
 
Registered: Jul 2006
Posts: 57

Original Poster
Rep: Reputation: 15
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...
 
Old 07-25-2006, 09:39 PM   #10
billymayday
Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
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?

Last edited by billymayday; 07-25-2006 at 09:42 PM.
 
Old 07-26-2006, 08:27 AM   #11
eur0dad
Member
 
Registered: Jul 2006
Posts: 57

Original Poster
Rep: Reputation: 15
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.
 
Old 07-26-2006, 08:48 AM   #12
eur0dad
Member
 
Registered: Jul 2006
Posts: 57

Original Poster
Rep: Reputation: 15
Hrmm... I put a simple "echo Hi!" in the rc.local file for testing, and nothing got printed when I rebooted.
 
Old 07-26-2006, 11:11 AM   #13
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,299

Rep: Reputation: 138Reputation: 138
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.
 
Old 07-26-2006, 11:26 AM   #14
eur0dad
Member
 
Registered: Jul 2006
Posts: 57

Original Poster
Rep: Reputation: 15
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Make a script run at reboot Braynid Linux - Newbie 10 06-26-2006 10:10 AM
Can double-click the shell script and choose "Run in Terminal" in Redhat? edwardsiow Programming 2 05-22-2006 08:56 PM
Run shell script in RedHat after boot dmorse Linux - General 1 08-23-2005 01:54 PM
Desktop won't run after reboot mgrundy Linux - General 5 03-09-2005 07:35 AM
on Network Up Script run? On Battery power run script? v2-ncl Linux - General 0 12-08-2003 09:34 AM


All times are GMT -5. The time now is 09:45 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration