なんかてきとうに

わりと個人的な忘備録的ですよ。

Expect的な処理は平行実行させると速いですね

&入れてwaitするだけでこの違い

平行実行するコード

#!/bin/bash
. ${0%/*}/.password
TMP=$(mktemp -d)
trap "rm -rf $TMP" 0
for i in $(cat list.txt);do
    expect -c "
    spawn ssh $user@$i -o UserKnownHostsFile=/dev/null
    expect {
        yes/no { send yes\r ; exp_continue }
        -nocase password { send $passwd\r ; }
    }
    expect >
    send \"term len 0\r\"
    expect >
    send \"sh arp\r\"
    expect >
    " > $TMP/$i.log &
done
wait
cat $TMP/* > $(date +"%Y%m%d").log

実行速度

real    0m6.605s
user    0m0.107s
sys     0m0.071s

順次実行するコード

#!/bin/bash
. ${0%/*}/.password
TMP=$(mktemp -d)
trap "rm -rf $TMP" 0
for i in $(cat list.txt);do
    expect -c "
    spawn ssh $user@$i -o UserKnownHostsFile=/dev/null
    expect {
        yes/no { send yes\r ; exp_continue }
        -nocase password { send $passwd\r ; }
    }
    expect >
    send \"term len 0\r\"
    expect >
    send \"sh arp\r\"
    expect >
    " > $TMP/$i.log
done
cat $TMP/* > $(date +"%Y%m%d").log

実行速度

real    0m59.881s
user    0m0.134s
sys     0m0.070s