Read vars iteratively


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read vars iteratively
# 1  
Old 04-18-2016
Read vars iteratively

Hello,
I have a tab delimited list of 311 server & account names which I want to read those 2 variables and then connect to each server and get info on that particular job account. I've tried the following:

Code:
while read server acct; do
        printf "********$server\t $acct***********\n"
        ssh $server "grep $acct /etc/passwd" 
        done < srvr_acct.lst

But this code bailed on me after making the first connection. Seems like this would be a simple fix, but it's Monday and I am not seeing it.

Input file is in the format:
Code:
server1<tab>job account1
server2<tab>job account2
...

Can anyone help?

Thanks!

Last edited by Scrutinizer; 04-18-2016 at 01:34 PM.. Reason: code tags
# 2  
Old 04-18-2016
Try:
Code:
while read server acct<&3; do
        printf "********%s\t %s***********\n" "$server" "$acct"
        ssh $server "grep '$acct' /etc/passwd" 
        done 3<srvr_acct.lst

# 3  
Old 04-18-2016
Or use ssh -n ... so it does not suck from the while loop's stdin.
# 4  
Old 04-18-2016
working now!

That was the ticket. Thanks so much for both responses.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pairing the nth elements on multiple lines iteratively

Hello, I'm trying to create a word translation section of a book. Each entry in the word list will come from a set of linguistically analyzed texts. Each sentence in the text has the following format. The first element in each line is the "name" of the line (i.e. "A","B","C","D"). The... (12 Replies)
Discussion started by: John Lyon
12 Replies

2. Shell Programming and Scripting

Bin iteratively based on each row

Hi I have a file some thing like below. I want to bin the data. My Bin size is 100. items number HELIX1 75 HELIX6 160 HELIX2 88 HELIX19 114 HELIX5 61 HELIX4 167 it should consider each elemet under the number column and bin all the lines like below with 100... (7 Replies)
Discussion started by: and_y
7 Replies

3. Shell Programming and Scripting

Using records iteratively with increament

I am very new to unix. Trying to use a for loop for this task I have a file like this abc.uml ccc.uml ddd.uml rrr.uml kkk.uml . . . n.uml ( more than 10000) I want to read this file but just 5 names at a time and then again it should read next 5 names and agin next 5. this... (6 Replies)
Discussion started by: nnani
6 Replies

4. UNIX for Dummies Questions & Answers

using awk iteratively in a script to assign variable values

I have a log file that has certain fields that I want to evaluate, and depending on the value in those fields, I want to put the value of a different field in that line in a particular variable that I'll use later on down the log file. Sort of like setting a switch to change what I do with a bunch... (5 Replies)
Discussion started by: pts2
5 Replies

5. Shell Programming and Scripting

Read 2 $vars from file line by line

Need some help with the following Bourne Shell script. The script is only looping one time and then stops. The script should loop as many times as there are entries in the input file = $FILE_LIST line by line. The file has the path to a source file and the destination directory where the file... (1 Reply)
Discussion started by: Muga801
1 Replies

6. UNIX for Dummies Questions & Answers

How to iteratively copy *.jar files

Hello, I want to copy all *.jar files from a parent tree structure, traversing all sub directories, into the traget dir. What shud be the command for that. I tried below command from the source parent dir cp -r *.jar pathtotargetdir but get the error '*.jar : No such file or... (1 Reply)
Discussion started by: New2
1 Replies

7. Shell Programming and Scripting

NEW: need help with nawk using -v vars

I'm trying to pass nawk a shell variable to be used in a pattern match. I can't get this work. I'm calling nawk from a /bin/sh I want that when somebody enters Trunk Group in variable TGR so it goes into nawk variable TG. echo "Enter TRUNK GROUP:" read TGR cat... (20 Replies)
Discussion started by: wakhan
20 Replies

8. Shell Programming and Scripting

Passing Vars between scripts

Im running a script that runs scripts within it self and i need to pass vars made in the original script to scripts run within it and the only way i can think to do it is right the string to a file and read the file in the script (4 Replies)
Discussion started by: rcunn87
4 Replies

9. Shell Programming and Scripting

need help with nawk using -v vars

I'm trying to pass nawk a shell variable to be used in a pattern match. I can't get this work. I'm calling nawk from a /bin/sh echo " Input file: \c" read var1 echo " Input: \c" read var2 nawk -F"|" -v x=$1 ' BEGIN $15 ~ /^'$var2'/ {print $2}' var1 {apary=$15; bparty=$23; time=$4;... (3 Replies)
Discussion started by: amon
3 Replies
Login or Register to Ask a Question