シェルスクリプトを介して別のサーバーにログインする方法

シェルスクリプトを介して別のサーバーにログインする方法

他のサーバーのディスク使用量がしきい値を超えていることを確認するスクリプトを作成しています。ただし、スクリプトを実行すると正しい出力が提供されず、ユーザーのパスワードのみを求めます。

私が持っているスクリプトは次のとおりです。

#!/bin/sh
USERNAMES=("username-for hostname1" "username-for hostname2")
PASSWORDS=("passwd-for hostname1" "passwd-for hostname2")
output1=/tmp/disk-usage.out
echo "---------------------------------------------------------------------------"
echo "HostName            Filesystem                Size Used Avail Use% Mounted on"
echo "---------------------------------------------------------------------------"
for server in `more /imp/scripts/servers.txt`----list of the servers
do
output=`ssh $server df -Ph | tail -n +2 | sed s/%//g | awk '{ if($5 > 10) print $0;}'`
echo "$server: $output" >> $output1
done
cat $output1 | grep G | column -t
rm $output1

私に提供される結果は次のとおりです。sh tt.sh

---------------------------------------------------------------------------
HostName            Filesystem                Size Used Avail Use% Mounted on
---------------------------------------------------------------------------
root@hostname1's password:

root@hostname2's password:

10.89.218.179:  /dev/mapper/vg_vm-lv_root  5.5G  2.6G  2.7G  50  /




__________________________________________________________________________________________________________

ベストアンサー1

問題は、cat $output1 | grep G | column -tサイズに対してのみgrepが欲しいGが、予想される出力では出力も見たいと思うということですM。このgrepコマンドを削除するかgrep -- [GM]、 。

おすすめ記事