The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
running a batch file in loop aemunathan Shell Programming and Scripting 1 05-21-2008 02:11 AM
SFTP in batch Mode ilok AIX 1 08-28-2007 01:25 AM
Sftp in Batch Mode sivaemn UNIX for Advanced & Expert Users 2 07-01-2007 06:52 AM
su command in batch mode Rajesh Gohad Shell Programming and Scripting 3 01-26-2007 12:54 AM
SFTP in batch mode mlim1111 Shell Programming and Scripting 5 01-23-2006 04:03 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-28-2007
DaveCutler DaveCutler is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 3
SSH in batch mode and File-Handles in a loop

Hi all
I try to execute SSH commands on several hosts in a while-loop.

There seems to be a problem with file-handle, first cycle works correct but no other one will follow due to the while condition is false even that there are many more host entries (lines) in all_hosts.dat.

#!/usr/bin/ksh
exec 0<all_hosts.dat
while read line
do
echo "...executing on host :" $line
ssh $line 'ls -la /tmp' # execution aborts after the first cycle
###pwd | ssh $line 'ls -la /tmp' # continues for each entry of all_hosts.dat
done # <all_hosts.dat
#


Any clue?
Any pointer to explaining tutorials about file handles?


MTIA

Dave
  #2 (permalink)  
Old 03-30-2007
ennstate ennstate is offline
Registered User
  
 

Join Date: Mar 2007
Location: Chennai
Posts: 222
I too get the same error,ie the SSH session is entered once, in case of while loop.

But it doesnot seems to happen if i use for inplace of while

for host in $(</tmp/hosts); do
echo "Executing on the $host"
ssh $host 'ls -lrt /tmp'
echo $host
done

cat /tmp/hosts
user1@localhost
remote@localhost
others@localhost

Gurus,
Help us why did the code as in OP using the while doesnot work,but using the for loop is works?

Thanks
Nagarajan Ganesan
  #3 (permalink)  
Old 03-30-2007
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361

The problem is that ssh is reading from stdin.

Either have the loop reading from another file descriptor or redirect the stdin of ssh from somewhere else, e.g. /dev/null

  #4 (permalink)  
Old 04-03-2007
DaveCutler DaveCutler is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 3
Thumbs up

... and
Code:
ssh -n 'command ...'
as written in the man page was the solution.

tks Chris
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0