Sponsored Content
Top Forums Shell Programming and Scripting Problem sshing to multiple servers while in a loop Post 302427487 by cfajohnson on Sunday 6th of June 2010 03:26:23 PM
Old 06-06-2010
Quote:
Originally Posted by DeCoTwc
I have the following block from a script (it's not the entire script, but I'm confident it's all that is pertinent)

Code:
echo "$SESSIONS"|while read ID;do
ASSETID=$(echo "$ERRORS"|grep -i "$ID"|grep FX_Media_Session_Playlist::init_playlist|grep -i asset_id=|awk '{print $11}')
BLADE=$(echo "$ERRORS"|grep -i "$ID"|grep FX_Media_Session_Playlist::init_playlist|grep -i asset_id=|awk '{print $1}'|tr -d ":")
#psh $BLADE "grep "$ASSETID" /opt/VideoServer/logs/streamer_log.txt|head -1|awk '{print $8}'"
echo "$ASSETID is on $BLADE"
done


First, format your code so that it is more easily readable:
Code:
echo "$SESSIONS" |
 while read ID;do
   ASSETID=$(
     echo "$ERRORS" |
     grep -i "$ID"  |
     grep FX_Media_Session_Playlist::init_playlist |
     grep -i asset_id= |
     awk '{print $11}'
     )

   BLADE=$(
     echo "$ERRORS" |
     grep -i "$ID" |
     grep FX_Media_Session_Playlist::init_playlist |
     grep -i asset_id= |
     awk '{print $1}'|tr -d ":"
     )

   #psh $BLADE "grep "$ASSETID" /opt/VideoServer/logs/streamer_log.txt | head -1 | awk '{print $8}'"
   echo "$ASSETID is on $BLADE"
 done

Then quote variable references:
Code:
psh "$BLADE" "grep $ASSETID /opt/VideoServer/logs/streamer_log.txt | head -1 | awk '{print $8}'"

You have 6 calls to grep and two to awk for every iteration of the loop. It would probably be more efficient to process the input before entering the loop, but you haven't supplied the contents of $SESSIONS, so it may not be.
Quote:
which returns:

Code:
[root@xcat01 utils]# ./xxx -y
asset_id=269939 is on p2b023
asset_id=269944 is on p1b007
asset_id=269314 is on p1b008
asset_id=266224 is on p1b006
asset_id=264377 is on p2b006
asset_id=265144 is on p1b008
asset_id=269455 is on p2b020

However, when I uncomment the shh command and comment out the echo command, it only goes through the first asset ID in the loop, and then exits out of the script.
Code:
[root@xcat01 utils]# ./xxx -y
p2b023: 06/05/10 11:59:55.847   I S10.250.18.185         STREAMER         0  AGABAAAALHEHKAME  \
FX_Live_Asset_Ingestion_Allocate_Service::make_reply Id=AGABAAAALHEHKAME asset_id=269939
[root@xcat01 utils]#

I've tried wrapping the SSH in every combination of single quotes and double quotes I can think of, and it always does just the first value from the loop and then exits. I'm stumped.

It shouldn't in this case (because there's a command), but ssh normally reads from the standard input, so it would read the entire output of "echo".

If the problem persists after fixing the quoting, try adding the -n option to ssh.
Quote:
Note: it says psh, but that's because this is being done from an xcat machine. It should work exactly the same as ssh, and in an attempt to debug, I tried using ssh, and it was the same problem.

Note2: In the final version, the ssh command will be in a variable,

That could make quoting even more problematic, unless it is only the command itself in the variable and not the arguments.
Quote:
and I'll be awking out a column of what it retuns (SESSIONID=$(ssh blade grep yadda yadda|awk '{print $9}'). I don't know if that matters.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

rsh to change multiple ip in multiple servers?

good day. i jsut wanted to know what is the best script or the best way changing a lot of Ip's in all servers. Do you have any idea? im using awk to change IP,what if, you have lots of servers. You need to change it one by one? It will take time to change it manually. (2 Replies)
Discussion started by: kenshinhimura
2 Replies

2. Shell Programming and Scripting

SSHing from a shell script

I want to connect to a remote server which I have a mySQL DB on, and do a mysqldump so I have a backup. I will likely schedule this with CRON to run every night. However, to make any changes to the mySQL server I have to SSH onto it, binding my local mySQL port to the remote one. Is this... (1 Reply)
Discussion started by: eludlow
1 Replies

3. Shell Programming and Scripting

Loop through the accounts and servers

Hi everyone, I am trying to use loop (for loop but can be any loop) which will read from the file (text file) which will have 2 column one for account and another for server which kind of look like this account1 server1 account2 server2 account3 server1 account4 server1 5 server3 6 server2... (1 Reply)
Discussion started by: pareshan
1 Replies

4. Shell Programming and Scripting

login into multiple servers through script is having some problem

Hi Everybody, I am bit new to shell scripting. I need some help in my script. I have to login into 15 servers and check some logs daily. For that I've written one shell script, somewhere it is having some problems. After log into the first server, the script is not going with the next steps.... (6 Replies)
Discussion started by: raghu.iv85
6 Replies

5. Shell Programming and Scripting

SSHing with multiple hops

Hi, I have got a shell script, which fails to run properly.. I am getting the following error: "Pseudo-terminal will not be allocated because stdin is not a terminal. Permission denied (gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive)." I SSH to the machine and then run the... (1 Reply)
Discussion started by: LinuxUser2008
1 Replies

6. UNIX for Dummies Questions & Answers

Problem with multiple grep in bash loop

Hello, I am trying to create a matrix of 0's and 1's depending on whether a gene and sample name are found in the same line in a file called results.txt. An example of the results.txt file is (tab-delimited): Sample1 Gene1 ## Gene2 ## Sample2 Gene2 ## Gene 4 ## Sample3 Gene3 ... (2 Replies)
Discussion started by: InfoSeeker2
2 Replies

7. Shell Programming and Scripting

Ssh to an array of servers in a for loop

There are 4 remote hosts that I have stored in an array. A ssh trust has been created from the local host to each of the remote hosts. I am trying to ssh to each of the servers in a for loop as shown below. declare -a host host}]="server1" host}]="server2" host}]="server3" ... (9 Replies)
Discussion started by: Sree10
9 Replies

8. Shell Programming and Scripting

Reset while loop to loop same file multiple times

Hi, I want to read file multiple times. Right now i am using while loop but that is not working. ex. While read line do while read line2 do echo stmt1 #processing some data based on data., done < file2.txt done < file1.txt # This will have 10... (4 Replies)
Discussion started by: tmalik79
4 Replies

9. UNIX for Advanced & Expert Users

SSHing into an IP restricted server via another machine

Hi, Apologies if this belongs in the beginner area. So.. The server I need to log into only allows logins from certain IP addresses. One of those IP's is my home computer, I can easily ssh into my home computer from elsewhere, and would then try to login to my work computer from there, but it... (1 Reply)
Discussion started by: Buckaroo Banzai
1 Replies

10. UNIX for Beginners Questions & Answers

How to apply the update statement in multiple servers on multiple dbs at a time .?

Hi , Can any please help the below requirement on all multiple servers and multiple dbs. update configuration set value='yes' ;1) the above statement apply on 31 Databases at a time on different Ip address eg : 10.104.1.12 (unix ip address ) the above ip box contains 4 db's eg : db... (2 Replies)
Discussion started by: venkat918
2 Replies
All times are GMT -4. The time now is 07:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy