expect

expect -c "spawn ssh map@host cat /etc/passwd ;expect $* echo $*"bash

 

#!/bin/bash

auto_login_ssh(){
    host=$1
    expect -c "set timeout 10;
            spawn ssh map@$host ;
            expect {
                password: {exit 1}
            }
    "
}
auto_login_ssh $1

批量獲取有至少2個 ssd 盤使用率小於10%的機器列表ssh

 

#!/bin/bash

bns_file =$1

if [[ -z $bns ]] ;then 
    echo 'service bns is empty!'
    exit 0  
fi

host_list=`cat $bns_file|cut -f 2|grep gzns|grep -E -v 'guoke|orcp'`

rs_file="ssd_gt2_$bns"

[ -f $rs_file ] && echo "rm -rf $rs_file"

for h in $host_list;do
    if [ -z $h ];then
        break   
    fi
    echo [$i]$h
    sh ssh_exp.sh $h 
    if [ $? -eq 0 ];then
        echo "[ok]"
        util_ssd_a=`ssh $h df -h|grep '/ssd'|awk '{printf("%s:%s\n",$5,$6)}'`
        util_ssd=($util_ssd_a)
        echo "$h:${util_ssd[@]}"
        num=0   
        for i in ${util_ssd[@]};do
            echo "i:$i"
            ssd=`echo $i|cut -d : -f 2 `
            util=`echo $i|cut -d : -f 1|cut -d % -f 1`
            echo "util:$util"
            if [ $util -lt 10 ]; then 
                num=$(($num+1))
            fi      
        done    
        if [ $num -gt 1 ];then
            echo "$h:${util_ssd[@]}" >>$rs_file
        fi      
    fi
done
相關文章
相關標籤/搜索