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

Thread Tools Search this Thread Display Modes
Old Unix and Linux 02-11-2013   -   Original Discussion by surender reddy
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


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 Unix and Linux 02-11-2013   -   Original Discussion by surender reddy
balajesuri's Unix or Linux Image
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
Join Date: Apr 2009
Last Activity: 8 November 2017, 2:32 AM EST
Location: India
Posts: 1,976
Thanks: 31
Thanked 574 Times in 547 Posts
Try this (be wary, this is not so secure):

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

Sponsored Links

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