Looping not completing in shell script | Unix Linux Forums | Shell Programming and Scripting

  Go Back    

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

Looping not completing in shell script

Shell Programming and Scripting

Closed Thread    
Thread Tools Search this Thread Display Modes
Old 02-11-2013
surender reddy surender reddy is offline
Registered User
Join Date: Jan 2013
Last Activity: 4 March 2013, 3:04 AM EST
Posts: 36
Thanks: 10
Thanked 0 Times in 0 Posts
Looping not completing in shell script


Iam using below code to login to servers to get cpu utilisation. but output is coming for only one server. code is below
HTML Code:
root@blr-svr-oclan-01 # more SSSC_CPU_UTIL1.sh
while read line; do
IDLE=`/usr/local/bin/sshpass -p 'xxx' ssh xxx@$line 'sar 2 2' | grep Average | cut -c38-40`
USAGE=`expr 100 - $IDLE`
echo $USAGE
done< sssc_ips.txt

HTML Code:
root@blr-svr-oclan-01 # more sssc_ips.txt
HTML Code:
root@blr-svr-oclan-01 # sh  SSSC_CPU_UTIL1.sh sssc_ips.txt
output is coming as below
HTML Code:
sample output of command sar 2 2 is given below

root@blr-svr-netap-01 # sar 2 2

HTML Code:
SunOS blr-svr-netap-01 5.10 Generic_137111-08 sun4u    02/11/2013

16:52:16    %usr    %sys    %wio   %idle
16:52:18      52       5       0      43
16:52:20      53       5       0      42

Average       53       5       0      42
please help to get the output for all servers and ip address of servers in output
Sponsored Links
Old 02-11-2013
balajesuri's Avatar
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
Join Date: Apr 2009
Last Activity: 26 February 2015, 7:48 PM EST
Location: India
Posts: 1,854
Thanks: 27
Thanked 532 Times in 510 Posts
Try this (be wary, this is not so secure):

sshpass -p 'passwd' ssh -o StrictHostKeyChecking=no user@hostname.com <commands>

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
C Shell Script: While function not fully looping notluckyhannah Shell Programming and Scripting 0 07-20-2011 02:26 AM
Looping through a shell script with sql statements novice82 Shell Programming and Scripting 4 10-08-2009 11:12 PM
shell script exiting before completing welldone Shell Programming and Scripting 6 07-02-2009 03:56 PM
Convert shell script for looping le0pard13 Shell Programming and Scripting 4 06-07-2007 08:42 PM
looping through a variable in a shell script ramachandranrr Shell Programming and Scripting 1 03-04-2007 08:02 PM

All times are GMT -4. The time now is 08:25 AM.