Te dejo un ejemplo mio. (Uso expect para automatizar tareas de networking: conectar mediante telnet o ssh, hacer algo ...):
fuente:
Scripting – Linux -Networking: Script desatendido (expect) de backup de la running-config de un Cisco sobre un servidor Tftp #!/bin/bash -f
# ./backup_cisco.sh ipcisco usuario pass passpriv iptftp
# by JavCasta 2.009 – Script backup Cisco runningconfig to tftp
if ! [ $# -eq 5 ]; then
echo “Necesitas pasar 5 parámetros: ipcisco usuario pass passpriv iptftp”
exit
fi
IPCISCO=$1
USUARIO=${2}”\r”
PASS=${3}”\r”
PASSPRIV=$4
IPTFTP=${5}”\r”
echo “#!/usr/bin/expect -f” > temp.exp
echo “set force_conservative 0 ;” >> temp.exp
echo “if {\$force_conservative} {” >> temp.exp
echo “ set send_slow {1 .1}” >> temp.exp
echo “ proc send {ignore arg} {” >> temp.exp
echo “ sleep .1″ >> temp.exp
echo “ exp_send -s — \$arg” >> temp.exp
echo “ }” >> temp.exp
echo “}” >> temp.exp
echo “set timeout -1″ >> temp.exp
echo “spawn telnet “$IPCISCO >> temp.exp
echo “match_max 100000″ >> temp.exp
echo “expect -exact \”Username: \”" >> temp.exp
echo “send — \”$USUARIO\”" >> temp.exp
echo “expect \”Password: \”" >> temp.exp
echo “send — \”$PASS\”" >> temp.exp
echo “expect \”>\”" >> temp.exp
echo “send — \”enable\r\”" >> temp.exp
echo “sleep .1″ >> temp.exp
echo “expect \”Password: \”" >> temp.exp
echo “send — \”$PASSPRIV\r\”" >> temp.exp
echo “expect \”#\”" >> temp.exp
echo “send — \”copy ru tftp\r\”" >> temp.exp
echo “expect \”Address or name of remote host\”" >> temp.exp
echo “send — \”$IPTFTP\”" >> temp.exp
echo “expect \”Destination filename\”" >> temp.exp
echo “send — \”\r\”" >> temp.exp
echo “expect \”#\”" >> temp.exp
echo “send — \”exit\”" >> temp.exp
chmod +x temp.exp
sudo ./temp.exp
#echo $*