rsh command in a while loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting rsh command in a while loop
# 1  
Old 11-18-2003
rsh command in a while loop

Hi ,

reading a "file1" with 2 data in each line (VAR1 and VAR2) , i'm using a while loop like this :

cat file1|awk '{print $1,$2}'|while read VAR1 VA2
do
echo $VAR1
echo $VAR2
done

as this example shows , it works but if between do and done i use
a "rsh" command , the script reads only the first line and exits.

It works just like if it change to another memory space , maybe i should use "exec" command but i don't know how !!!!!

Someone has an idea ????

thanks in advance

Christian
# 2  
Old 11-18-2003
Don't know what shell you were using - the code you posted did not work in ksh - and got only the first variable in sh. Csh didn't work at all.

This works:

#!/bin/ksh
while read -r eachline
do
VAR1=`echo $eachline|awk '{print $1}'`
VAR2=`echo $eachline|awk '{print $2}'`
rsh -l $VAR2 $VAR1 uptime
done < ./file1
exit

format of file1
firstsystemname useracccount
seconsystem useraccount
thirdsystem useraccount
# 3  
Old 11-19-2003
Thanks ,

i'm using AIX with ksh too ,

i tried your code and it does the same thing as mine , after reading the first line of "file1" and executing the rsh command , it doesn't continue on next line !

if i comment the "rsh" line , the loop is ok

i don't understand anything !!!

christian
# 4  
Old 11-19-2003
Maybe someone with AIX access can assist. Mine was run on Solaris.
# 5  
Old 11-19-2003
That's right , i've found !!

Thanks again for your help !!!! ( and PERDERABO changepass script)

christian

modifications in red

#!/bin/ksh

exec 4>&1

while read -r eachline
do
VAR1=`echo $eachline|awk '{print $1}'`
VAR2=`echo $eachline|awk '{print $2}'`

rsh $VAR1 -l $VAR2 uptime >&4 2>&4 |&

wait

done < ./file1
exit

format of file1
firstsystemname useracccount
seconsystem useraccount
thirdsystem useraccount
# 6  
Old 11-19-2003
Gack! That is a terrible solution. You don't want to use a coprocess for this. Your whole problem is that you need -n on the rsh. But here is what I would have done...
Code:
#! /usr/bin/ksh
typeset -R19 fhost
exec < file
while read host user ; do
     fhost=${host}:
     echo "$fhost $(rsh $host -l $user -n uptime)"
done
exit 0

# 7  
Old 11-19-2003
Thanks a lot !


"how to do it simple when i can do it very complicated" is my saying (joke)

my script is quite finish and also more legible !

christian
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rsh reboot in a loop?

Hi folks. I'm trying to get the following script working for rebooting a bunch of clients. Up to now I've been using PSSH, but when they all startup again at the same time I get a few mount problems. So, I'm trying to stagger the reboot command. I know reboot will depend on what's running at... (3 Replies)
Discussion started by: MuntyScrunt
3 Replies

2. Shell Programming and Scripting

awk, double variable, for loop and rsh

Hello folks, I've a (perhaps) simple question. In a text file I've : server_name1: directory1 server_name2: directory2 server_name3: directory3 I want to make a loop that lets me connect and operate on every server: rsh server_name1 "ls -l directory1" I've tried with awk,... (6 Replies)
Discussion started by: gogol_bordello
6 Replies

3. Shell Programming and Scripting

rsh script with inside a for loop

hi everyone, I have the following problem: the foreach loop inside rsh doesn'work. I have tried the for command but it's not recognized. with the foreach command I don't receive any error, but it doesn't really make the cycle, ignoring the foreach and executing 1 time the echo command. Anyone has... (5 Replies)
Discussion started by: trekianov
5 Replies

4. Shell Programming and Scripting

rsh breaking me out of loop

Hey all I have two scripts, one script containing the guts of my code. The other simply loops through a list, calling the other script on each iteration. Problem is when I add the line `/usr/bin/rsh -l root $HOSTNAME ""` to my main script, the loop never seems to exectute any more... (1 Reply)
Discussion started by: mark007
1 Replies

5. Linux

rsh command

we want to execute remote script via rsh (we just only should use rsh except others),but rsh command can not set environment variable for specify user, then scripts can not be executed correctly,anyone knows how to fix this problem? thanks. (8 Replies)
Discussion started by: Frank2004
8 Replies

6. UNIX for Dummies Questions & Answers

rsh command

Hi, I am a beginner and i want to seek help I want to use the rsh command. Is there a possibility that i can do it without the system password I am planning to make a csh script that could browse/copy files from diferent workstations. thank you.... (5 Replies)
Discussion started by: wramonzon
5 Replies

7. UNIX for Advanced & Expert Users

While read loop and rsh

Hi all I have a while read loop that I use to process a file line by line. The reason I am using this is due the fact that I have spaces in the line and a for loop treats the space as a delimeter for the next record. In this while loop I have a rsh. It appears that cos of the rsh, I never get... (1 Reply)
Discussion started by: 104234
1 Replies

8. Shell Programming and Scripting

rsh and for loop

hi I wanted to use the for loop structure in tandem with rsh command and the result to be redirected into a local .lst file within a shell script . Tried the following but does not help :confused: . rsh ABCD "cd /bosp/local/home/linus/;for i in `ls -ltr | grep ^- | awk {'print $9'}` do... (4 Replies)
Discussion started by: newbee2005
4 Replies

9. UNIX for Dummies Questions & Answers

rsh command

Hi, I'm performing a data migration from an Ingres db to an Oracle db. The ingres database lives on a unix host running "UNIX(r) System V Release 4.0 (SunOS 5.5.1) ", while the Oracle database lives on another unix host running "SunOS 5.8". Part of the migration is to remotely run Oracle's... (1 Reply)
Discussion started by: strpeski
1 Replies

10. UNIX for Dummies Questions & Answers

Rsh command

Newbie here, I want to add a line to our 3D rendering scripts that will send an email to the animators once a scene has finished rendering. The 3D scripts are on the client hosts and the sendmail setup on the server. I tried using a rsh line in the script as follows rsh root@blah echo... (2 Replies)
Discussion started by: flamethrower
2 Replies
Login or Register to Ask a Question