LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-13-2008, 05:01 PM   #1
maas187
Member
 
Registered: Aug 2008
Location: Yemen
Distribution: Fedora, CentOS, RedHat , OpenFiler, ESXI
Posts: 225

Rep: Reputation: 32
Smile Startup Script ...


hi to all ,
i need to write a script that will run everytime my system reboot.
i have few commands that i need them to be executed when the server boot up

PS. iam good with Bash Scripts .
 
Old 08-13-2008, 05:03 PM   #2
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
If it's some type of daemon, this depends on what distribution you're using. Most reside in /etc/init.d or /etc/rc.d

If it's just a few commands that don't run as a service or the like, simply place the script or commands in your rc.local file to get invoked at bootup.
 
Old 08-13-2008, 05:06 PM   #3
maas187
Member
 
Registered: Aug 2008
Location: Yemen
Distribution: Fedora, CentOS, RedHat , OpenFiler, ESXI
Posts: 225

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by trickykid View Post
If it's some type of daemon, this depends on what distribution you're using. Most reside in /etc/init.d or /etc/rc.d

If it's just a few commands that don't run as a service or the like, simply place the script or commands in your rc.local file to get invoked at bootup.

iam Using Fedora 8 .

so it must be init , and about the deamon , well maybe keep it last so al services are running .


commands are ,

1 - ssh: to a remote server.
2 - mail: as an alert.
3 - iptables: for routing .
 
Old 08-13-2008, 05:09 PM   #4
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Quote:
Originally Posted by maas187 View Post
1 - ssh: to a remote server.
2 - mail: as an alert.
3 - iptables: for routing .
These would be good candidates for rc.local, not their own customized init startup script to me. Why would you need to ssh into a remote server out of curiosity that is in a startup script?
 
Old 08-13-2008, 05:12 PM   #5
maas187
Member
 
Registered: Aug 2008
Location: Yemen
Distribution: Fedora, CentOS, RedHat , OpenFiler, ESXI
Posts: 225

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by trickykid View Post
These would be good candidates for rc.local, not their own customized init startup script to me. Why would you need to ssh into a remote server out of curiosity that is in a startup script?
well, too keep things short , iam using ssh to access the web. since my ISP blocks most sites.
with this command :
ssh -D 8998 username@remoteserver.com
which i have set up on my browser settings as well ,

where could i find this rc.local ?
 
Old 08-13-2008, 05:19 PM   #6
maas187
Member
 
Registered: Aug 2008
Location: Yemen
Distribution: Fedora, CentOS, RedHat , OpenFiler, ESXI
Posts: 225

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by maas187 View Post
well, too keep things short , iam using ssh to access the web. since my ISP blocks most sites.
with this command :
ssh -D 8998 username@remoteserver.com
which i have set up on my browser settings as well ,

where could i find this rc.local ?
thank man for the info .. i found it ..

its /etc/rc.d/rc.local

,, do you thing that ssh will work ???
 
Old 08-13-2008, 05:37 PM   #7
maas187
Member
 
Registered: Aug 2008
Location: Yemen
Distribution: Fedora, CentOS, RedHat , OpenFiler, ESXI
Posts: 225

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by maas187 View Post
thank man for the info .. i found it ..

its /etc/rc.d/rc.local

,, do you thing that ssh will work ???
well, guys i tried to put the SSH command in the rc.local , when the system boots up , it logs to the remote server and jams after i cant login to the system anymore . had to boot into level 3 to exit the SSH connection .. any ideas ?????
 
Old 08-13-2008, 05:42 PM   #8
chort
Senior Member
 
Registered: Jul 2003
Location: Silicon Valley, USA
Distribution: OpenBSD 4.6, OS X 10.6.2, CentOS 4 & 5
Posts: 3,660

Rep: Reputation: 76
Code:
ssh -nND 8998 -i /path/to/privatekey username@remoteserver.com &
Note that your privatekey cannot require a passphrase if you do this.

I haven't actually tested that this works with an init script. It's possible that you might need to add nohup in front of ssh.
 
Old 08-13-2008, 05:46 PM   #9
maas187
Member
 
Registered: Aug 2008
Location: Yemen
Distribution: Fedora, CentOS, RedHat , OpenFiler, ESXI
Posts: 225

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by chort View Post
Code:
ssh -nND 8998 -i /path/to/privatekey username@remoteserver.com &
Note that your privatekey cannot require a passphrase if you do this.

I haven't actually tested that this works with an init script. It's possible that you might need to add nohup in front of ssh.
sorry my dear friend . but what is a nohup ???

and when i added the ssh to the rc.local i could see it connected to the server , but the problem is that i cant be a local user anymore unless i exit ???
is there a way to keep it running in the background ???
 
Old 08-13-2008, 06:04 PM   #10
maas187
Member
 
Registered: Aug 2008
Location: Yemen
Distribution: Fedora, CentOS, RedHat , OpenFiler, ESXI
Posts: 225

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by maas187 View Post
sorry my dear friend . but what is a nohup ???

and when i added the ssh to the rc.local i could see it connected to the server , but the problem is that i cant be a local user anymore unless i exit ???
is there a way to keep it running in the background ???
hi , i tried , nohup , and "-n" and "-s" ,,, still no use ??

any ideas ??
thankx in advance ? ?
 
Old 08-13-2008, 06:17 PM   #11
grepmasterd
Member
 
Registered: Aug 2003
Location: Seattle
Distribution: ubuntu, lately
Posts: 182
Blog Entries: 1

Rep: Reputation: 35
just a hunch, but...

write a script that will do this and fork itself into the background.

test it a couple times from the command line to make sure it works and backgrounds appropriately. then call the script from rc.local
 
Old 08-13-2008, 06:20 PM   #12
grepmasterd
Member
 
Registered: Aug 2003
Location: Seattle
Distribution: ubuntu, lately
Posts: 182
Blog Entries: 1

Rep: Reputation: 35
oh, and nohup means that the command will run immune to 'hangups'. it won't be attached to the shell script from which it was launched so the script should be able to exit. (often, shells wont exit completely if there are attached processes still running).
 
Old 08-13-2008, 06:21 PM   #13
maas187
Member
 
Registered: Aug 2008
Location: Yemen
Distribution: Fedora, CentOS, RedHat , OpenFiler, ESXI
Posts: 225

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by grepmasterd View Post
just a hunch, but...

write a script that will do this and fork itself into the background.

test it a couple times from the command line to make sure it works and backgrounds appropriately. then call the script from rc.local
could u please provide syntax ???
 
Old 08-13-2008, 06:24 PM   #14
grepmasterd
Member
 
Registered: Aug 2003
Location: Seattle
Distribution: ubuntu, lately
Posts: 182
Blog Entries: 1

Rep: Reputation: 35
another thought: use 'screen'

Quote:
screen -d -m ssh -nND 8998 -i /path/to/privatekey username@remoteserver.com
note: no backgrounding needed

screen rules.
 
Old 08-13-2008, 06:26 PM   #15
maas187
Member
 
Registered: Aug 2008
Location: Yemen
Distribution: Fedora, CentOS, RedHat , OpenFiler, ESXI
Posts: 225

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by maas187 View Post
could u please provide syntax ???
ok . i get what u saying ..

Lol sorry this is like a chat room for me .

i tried
$ssh username@remoteserver.com -f "cd Folder" ...


but the thing is it runs and exits .. i checked the status with netstat -at ..

i need it to be running all the time ?
 
  


Reply

Tags
rclocal, screen, startup



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
'cannot stat' script in /etc/rc.d/, try to run script at startup quintan Linux - Software 1 11-21-2005 02:53 AM
How to call a script from a system startup script? jonatito Linux - Newbie 7 11-11-2005 09:40 PM
wi-fi startup script Nodren Linux - Wireless Networking 6 05-09-2005 08:56 AM
startup script djinniyah Linux - Newbie 2 09-18-2003 05:07 AM
What's a startup script? rdaves@earthlink.net Linux - Newbie 1 05-22-2001 03:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 04:36 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration