LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-29-2009, 11:52 AM   #1
JDska55
LQ Newbie
 
Registered: Jun 2009
Location: Iowa City, IA
Distribution: SuSE 11, ubuntu Hardy
Posts: 28

Rep: Reputation: 15
Executing commands on a remote machine


Hey all-
I'm wondering if there's a way to issue commands toa remote machine without having the terminal actaully log in to the remote machine. Basically, I want to tell the remote box to run a script that I scp'd into it earlier in the script. Here's what I'm thinking:
Code:
do
  addarray[$count]="$address"
  ((count++))
  rsync -e "ssh -i `echo ~`/.ec2/gsg-keypair" -avz /home/admin/data root@${address}:/root
  scp -i ~/.ec2/gsg-keypair ~/Kai-script root@${address}:/root
  ssh -i ~/.ec2/gsg-keypair root@${address}
done
I've been using the ssh and then executing the script on the remote machine, but that means I have to wait till it's done running before I can exit and get back into the script on my home machine. Since that takes about 2 hours, it's not exactly convenient . Any thoughts?

Cheers,
Jarrod
 
Old 06-29-2009, 12:29 PM   #2
Dinithion
Member
 
Registered: Oct 2007
Location: Norway
Distribution: Slackware 14.1
Posts: 446

Rep: Reputation: 59
Check out nohup, i.e. By using nohup commands can finnish after you logout. By adding a & to the command, it will be runned in the background. I thing you should be able to fix it that way
 
Old 06-29-2009, 01:18 PM   #3
farslayer
LQ Guru
 
Registered: Oct 2005
Location: Willoughby, Ohio
Distribution: linuxdebian
Posts: 7,232
Blog Entries: 5

Rep: Reputation: 190Reputation: 190
screen is your friend.

http://www.linuxdynasty.org/screen-howto-part-1.html

http://jmcpherson.org/screen.html

http://www.rackaid.com/resources/lin.../using-screen/
 
Old 06-30-2009, 01:18 PM   #4
JDska55
LQ Newbie
 
Registered: Jun 2009
Location: Iowa City, IA
Distribution: SuSE 11, ubuntu Hardy
Posts: 28

Original Poster
Rep: Reputation: 15
Hm... I don't think screen is what I'm looking for. I only need one terminal up locally, I just need to be able to exit from remote machines and have them keep running their script. i tried doing nohup bash myscript &, but it hung up for some reason, never returning me to the prompt...
 
Old 06-30-2009, 01:26 PM   #5
xxloaf
LQ Newbie
 
Registered: May 2007
Distribution: Debian
Posts: 10

Rep: Reputation: 0
Quote:
Originally Posted by JDska55 View Post
Hm... I don't think screen is what I'm looking for. I only need one terminal up locally, I just need to be able to exit from remote machines and have them keep running their script. i tried doing nohup bash myscript &, but it hung up for some reason, never returning me to the prompt...
This is still doable with screen.

Once you login to the remote machine execute "shell".

Once you are inside of the shell you can then execute your command, once you have done so you can detach the shell while the command still runs.

Code:
ctrl-a-d
This will detach the shell, even if you log out of the remote machine the command will still be running.

Once you return to the machine you just run 'screen -r' to bring the shell back.
 
Old 06-30-2009, 01:45 PM   #6
JDska55
LQ Newbie
 
Registered: Jun 2009
Location: Iowa City, IA
Distribution: SuSE 11, ubuntu Hardy
Posts: 28

Original Poster
Rep: Reputation: 15
Thanks for the tips! It appears that screen will work for this. The concept is still a bit hazy to me, but as long as it works, I'm okay with it. Thanks!

Last edited by JDska55; 06-30-2009 at 01:49 PM. Reason: not paying attention
 
Old 06-30-2009, 03:04 PM   #7
farslayer
LQ Guru
 
Registered: Oct 2005
Location: Willoughby, Ohio
Distribution: linuxdebian
Posts: 7,232
Blog Entries: 5

Rep: Reputation: 190Reputation: 190
The ability to re-attach to a screen session is one of the cool features, that I really like..

I used to host some game servers on Linux and would run them in screen sessions so I could remote into the system attach to the screen to manage the server, detach then log off the remote box.

I had a consultant remote into a system once and he ran a screen session which we then attached to locally so we could watch everything he did on the server.. Was rather slick.
 
  


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
executing vfs_write on remote machine, which other calls should be hooked? saumitra Programming 4 04-07-2007 11:44 PM
run commands in remote machine lhrt Linux - Software 2 01-13-2007 08:09 AM
Executing graphical programs on a remote machine dreamtheater Linux - Networking 9 10-13-2006 09:52 AM
bash - execute commands on a remote machine capture results, etc dkrysak Programming 1 11-18-2005 01:50 PM
executing shell commands in c++ true_atlantis Programming 2 10-01-2004 04:53 PM


All times are GMT -5. The time now is 02:47 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration