rsh script with inside a for loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting rsh script with inside a for loop
# 1  
Old 01-19-2006
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 ideas?

rsh host "cd a/b
exe<< stop
1
2
stop
exe2<<stop2
a
b
stop2
foreach ptcluster (30 35 40 45 50)
echo PTCLUS=$ptcluster
end
"

I have read read the following statement, but I don't know if it is the real issue:
"When this command is read from the terminal, the loop is read once prompting with `foreach? ' (or prompt2) before any statements in the loop are executed. If you make a mistake typing in a loop at the terminal you can rub it out."
# 2  
Old 01-19-2006
It's always good to try searches before asking. This was discussed a few days ago. Check here.

Cheers,

Keith
# 3  
Old 01-20-2006
suggestion

hi, thank you for the suggestion, but the thread you have pointed out is quite different from my issue:
I want to perform a loop inside the compound command. in any case I have tried the suggestion, but didn't worked.
Cheers Michele
# 4  
Old 01-20-2006
For one thing, try this:
$ xyz=hello
$ echo "xyz = $xyz"
xyz = hello
$
Shells look inside double quoted strings and replace variables. Your variable $ptscluster will be replaced before your local shell even locates the rsh command. This doesn't explain why you're not looping, but I'm not a csh expert. You should put scripts in an executable file, not in an argument to a command line. Once you use something like "rsh host ./remoteloop", all of the problems will vanish. Make sure you have a line like "#! /usr/bin/csh" in your remoteloop file. Note that you can create remoteloop locally, rcp it into place, chmod it, run it, and then remove it.
# 5  
Old 01-20-2006
I have tried this workaround (even if I see it as a defiance :-) ).
but another problem arised: i want to keep the control in the main script of the variable to be passed so I would like to pass them to the script.
this is the "inner" script:
#!/bin/sh
# loop through a set of numbers
# echo $pt
echo nome$1
echo pt$2
echo eta$3
for i in 1 2 ;
do ../herlib/hwuser<<stop ;
$1
$2 $3
$i
stop

done

when I do
$ ./forloop a b c
it works but when it is called by another script it fails to recognize the variables.
for example: I call the previous script (forloop) through
name=tt_25_5_0jet
pt=20
eta=0.6
./forloop<<stop
$name
$pt
$eta
stop

but don't work... any idea?
THANKS in advance Michele
# 6  
Old 12-06-2008
Use -n with rsh command & then you'r probelem will surely get solve.

EG: rsh host -n "cd a/b


Regards,
Lahiru Jeewantha


Quote:
Originally Posted by trekianov
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 ideas?

rsh host "cd a/b
exe<< stop
1
2
stop
exe2<<stop2
a
b
stop2
foreach ptcluster (30 35 40 45 50)
echo PTCLUS=$ptcluster
end
"

I have read read the following statement, but I don't know if it is the real issue:
"When this command is read from the terminal, the loop is read once prompting with `foreach? ' (or prompt2) before any statements in the loop are executed. If you make a mistake typing in a loop at the terminal you can rub it out."
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to write a Boolean variable which succeed and failed inside the if loop in shell script ?

I have if loop with multiple variable value check in if loop. How can i print only if loop satisfied variable and its value in shell script ? I dont want to check each variable in if loop. That makes my script larger. if ] then echo "Only satisfied variable with value" ... (3 Replies)
Discussion started by: prince1987
3 Replies

2. 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

3. Shell Programming and Scripting

Problem passing a search pattern to AWK inside a script loop

Learning, stumbling! My progress in shell scripting is slow. Now I have this doubt: I have the following file (users.txt): AU0909,on AU0309,off AU0209,on AU0109,off And this file (userson.txt) AU0909 AU0209 AU0109 AU0309 I just want to set those users on userson.txt to "off" in... (14 Replies)
Discussion started by: quinestor
14 Replies

4. Shell Programming and Scripting

help in running while loop inside a shell script

I have an input file at ./$1.txt with content of seq numbers like : 1234567890 1234589700 . . so on.. I need to take each seq nbr from the input file ,run the query below: select ackname,seqnbr from event where event_text like '%seqnbr( from the input file)' and redirect the... (11 Replies)
Discussion started by: rkrish
11 Replies

5. Shell Programming and Scripting

If inside while loop script error

#!/bin/bash var1=0 x=1 while do echo "Welcome $x times" var1=$(prstat -Lc 1 1 | nawk ' /^Total/ {print substr($8,1,length($8)-1)}') echo "$var1" if then break fi sleep 6 x=$(( $x + 1 )) done giving output: bash-3.00$ ./ch1.sh Welcome 1 times 5.90 (9 Replies)
Discussion started by: vivek1489
9 Replies

6. Shell Programming and Scripting

How to give a variable output name in a shell script inside a for loop

Hi all I run my program prog.c in the following way : $ ./prog 1 > output.txt where 1 is a user defined initial value used by the program. But now I want to run it for many a thousand initial values, 1-1000, and store all the outputs in different files. Like $ ./prog 1... (1 Reply)
Discussion started by: alice06
1 Replies

7. Shell Programming and Scripting

Using variables created sequentially in a loop while still inside of the loop [bash]

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

8. 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

9. 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

10. Shell Programming and Scripting

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... (6 Replies)
Discussion started by: Nicol
6 Replies
Login or Register to Ask a Question