NETWORK ENGINEER BLOG

Tips and Reviews for Engineers

sshpass について

sshpass*1 とは

コマンドラインで ssh 接続のパスワードを指定可能なツールになります。SSH 被接続装置へ1行でログインし、続けてコマンドを実行する事が可能です。ssh で接続できる装置であれば、基本的に利用する事が可能ですが、特に NetApp(7-Mode)は、display コマンドで grep に対応していないため便利です。

sshpass 使用例

snapshot 領域を省略した aggr 情報を表示

# sshpass -p Password ssh -l root Netapp df -Ag | grep -v snapshot
Aggregate                total       used      avail capacity
aggr0                  14000GB     9000GB     5800GB      61%
aggr1                  14000GB     6500GB     8000GB      44%
aggr4                  13000GB     3000GB    10000GB      22%
aggr3                  10000GB     3500GB     6700GB      35%
aggr5                  13000GB     3100GB    10000GB      23%
aggr6                  10000GB     3800GB     6000GB      37%

使用率 80% 以上のボリュームを抜粋して表示

# sshpass -p Password ssh -l root Netapp df -h | grep '[8-9][0-9]%\|100%'
/vol/vol1/              100MB       94MB     5496KB      95%  /vol/vol1/
/vol/vol2/              100MB       94MB     5496KB      95%  /vol/vol2/
/vol/vol3/              100MB       94MB     5496KB      95%  /vol/vol3/
/vol/vol4/              100MB       94MB     5492KB      95%  /vol/vol4/

以上

*1:Non-interactive ssh password authentication