0

I’m trying to create a shell script to get the server stats of 100 servers and load the details into a table.Initially I’m creating a parameter file which has the list of all the servers, then I ‘m connecting these servers through ssh and run df –k. ssh keys are already setup. Issues I’m facing is that I’m not able to associate server name to the result, I want server name added as a column to the df –k output. Also the output format cannot be loaded into a table as there is no delimiter or tab or space properly formatted to load. I have tried sed & various other options but no luck.

#!/bin/ksh
PARMFILE=/opt/sdw/scripts/db_scripts/server_stats.txt

value=$(<server_list1.txt)
echo "$value"
sourceservers=`grep =/opt/sdw/scripts/db_scripts/server_stats.txt |cut -d= -f2`

#Input array passed as parameter file to the script
set -A array_value $value
vLen=${#array_value[@]}
echo $vLen

for(( j=0; j<$vLen; j++))
do
#echo "${array_value[$j]}"
#ssh -q "${array_value[$j]}"; df -k
ssh -q "${array_value[$j]}" 'df -h' >> df.out
ssh -q "${array_value[$j]}" df -h | column -t  >> df1.out
ssh -q "${array_value[$j]}" df -k | tr -s " " | sed 's/ /, /g' | sed '1 s/, / /g' | column -t >> df3.out
 [[ ! $? = 0 ]] && echo Failure, errno $?, cannot connect to host "${array_value[$j]}" >> sshfailed.list
done 

Output

Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg00-lvol3 1.5G 434M 923M 32%

Desired output

Filesystem, Size, Used , Avail, Use%, Mounted on, Servername /dev/mapper/vg00-lvol3, 1.5G, 434M, 923M, 32%, / br724

4

1 回答 1

0

为了更好的可读性,放入"${array_value[$j]}"一个变量$server

然后在 sed 中,进行类似的替换sed "s/Mounted on/Mounted on $server/g"

于 2013-08-04T12:08:36.730 回答