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
    #1  
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

Hi,

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
#!/bin/sh
echo "CPU UTILIZATION"
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
inputfile

HTML Code:
root@blr-svr-oclan-01 # more sssc_ips.txt
172.30.3.42
172.30.3.64
172.30.19.42
172.30.19.38
HTML Code:
root@blr-svr-oclan-01 # sh  SSSC_CPU_UTIL1.sh sssc_ips.txt
output is coming as below
HTML Code:
CPU UTILIZATION
61
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
    #2  
Old 02-11-2013
balajesuri's Avatar
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 23 November 2014, 2:06 AM EST
Location: India
Posts: 1,833
Thanks: 25
Thanked 526 Times in 505 Posts
Try this (be wary, this is not so secure):

Code:
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 07:49 PM.