五月, 2014
利用shell批量执行telnet指令
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#!/bin/bash - #导出已经在用户列表 for x in `seq 0 99`; do mysql -uoss -poss_da -h{127.0.0.1} -P3306 databasename -Bse "select uid from users_$x" >> tmp/tmp_file_$$.txt; echo "processing table users_$x ..."; done #逐行处理临时文件 /usr/bin/expect <<EOF set timeout 2 spawn telnet 127.0.0.1 3307 `while read line; do echo expect \"\" echo send \"command=10011\&uid=$line\\\n\" echo expect \"*res=*\" echo exec sleep 1 done < tmp/tmp_file_$$.txt` expect eof EOF #处理完毕,删除临时文件 if [ -e tmp/tmp_file_$$.txt ]; then rm -fr tmp/tmp_file_$$.txt fi |