长时间运维,经常出现telnet 不通端口,长时间等待导致批量脚本运行时间较长,今天终于解决了:
#!/bin/bash
port=22
log=logs
echo "" > "$log/telnet_result.txt"
for i in $(cat ip_list.txt)
do
((count++))
echo "count=$count"
`echo -e '\xldclose\x0d' | timeout --signal=9 3 telnet $i $port >> "$log/telnet_result.txt"`
done
cat "$log/telnet_result.txt" | grep -B 1 \] | grep [0-9] | awk -F ' ' '{print $3}' |cut -d '.' -f 1,2,3,4 > "$log/telnet_alive.txt"
cat ip_list.txt "$log/telnet_alive.txt" | sort | uniq -u > "$log/telnet_die.txt"