tips:FTPやTELNETの自動化
created 2006-12-27 modified 2006-12-27
expect という tcl 拡張を利用する。
telnetscript.sh
#!/bin/bash HOST=127.0.0.1 USER=hoge PASS=fuga expect - <<EOF set timeout 20 spawn telnet $HOST expect "ogin: " ; send "$USER\r" if { "$PASS" != "" } { expect "assword: " ; send $PASS\r } expect ">" ; send "enable\r" expect "#" ; send "conf pr\r" expect "#" ; send "exit\r" expect "#" ; send "exit\r" expect ">" ; send "exit\r" EOFこんな調子。制御文などは tcl の素の機能でOK。