Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Looping not completing in shell script

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 02-11-2013
surender reddy surender reddy is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 17 September 2015, 9:55 AM EDT
Posts: 39
Thanks: 11
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 Unix and Linux 02-11-2013
balajesuri's Unix or Linux Image
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 1 December 2016, 8:47 AM EST
Location: India
Posts: 1,966
Thanks: 30
Thanked 567 Times in 543 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 Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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