LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 11-20-2009, 11:03 AM   #1
MOFH
LQ Newbie
 
Registered: Nov 2009
Posts: 17

Rep: Reputation: 0
SSH onto nodes in a loop and then get off


Ok I know this question has been asked before as I've read through the threads and I've also done this before but can't get it to work now

Simple question really:
log onto a list of nodes say node 2-5 see who's on and then leave
I have something like:
for u 2 3 4 5 ; do
ssh -n node$u (also tried rsh -n and just rsh and ssh)
echo $u
who
logout (or exit)
done

The problem is it logs onto the nodes but doesn't logoff. Is there something fundamentally wrong with this bash script?

Thanks
Mo
 
Old 11-20-2009, 11:27 AM   #2
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 15,102

Rep: Reputation: 2719Reputation: 2719Reputation: 2719Reputation: 2719Reputation: 2719Reputation: 2719Reputation: 2719Reputation: 2719Reputation: 2719Reputation: 2719Reputation: 2719
Quote:
Originally Posted by MOFH View Post
Ok I know this question has been asked before as I've read through the threads and I've also done this before but can't get it to work now

Simple question really:
log onto a list of nodes say node 2-5 see who's on and then leave
I have something like:
for u 2 3 4 5 ; do
ssh -n node$u (also tried rsh -n and just rsh and ssh)
echo $u
who
logout (or exit)
done

The problem is it logs onto the nodes but doesn't logoff. Is there something fundamentally wrong with this bash script?

Thanks
Mo
My guess would be that you're starting a new shell on the remote box, while the commands are in the shell-script on the local box. You initiate the new shell fine, but then it sits there.

Try putting the command on the SSH line, like:
Code:
ssh -n node$u "insert command name here"
That'll just attach and run that command, without opening a new shell on the remote end. You might also want to look at the "fanout" program (Google can show you the way...), or write a script using "expect", so it'll enter the commands as if you were typing them.
 
Old 11-20-2009, 11:41 AM   #3
MOFH
LQ Newbie
 
Registered: Nov 2009
Posts: 17

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by TB0ne View Post
My guess would be that you're starting a new shell on the remote box, while the commands are in the shell-script on the local box. You initiate the new shell fine, but then it sits there.

Try putting the command on the SSH line, like:
Code:
ssh -n node$u "insert command name here"
That'll just attach and run that command, without opening a new shell on the remote end. You might also want to look at the "fanout" program (Google can show you the way...), or write a script using "expect", so it'll enter the commands as if you were typing them.
Thanks!
I tried that and it seems to work though it gives a silly warning regarding "use exit instead of logout" (which is bad idea). I'll give the other things a go because I want it to take commands from my script instead of std input.

Mo
 
  


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
ssh program for a loop g4gopal@yahoo.com Programming 1 01-26-2009 07:13 PM
SSH Bash Loop m1ck Programming 7 01-31-2007 11:03 AM
SSH from master node to compute nodes w/out passwd haiders Linux - Networking 2 09-20-2006 12:50 PM
ssh across a bunch of nodes podollb Linux - Software 11 05-11-2004 04:35 PM
can ping but cannot ssh into nodes dogma Linux - Newbie 2 06-10-2003 07:41 PM


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