#===========autotelnet.sh==============
#!/bin/bash
if (( $# != 1 ))
then
echo " usage: address "
exit 1
fi
ip=
inp1=`cat param |grep "$ip" |awk '{ print }'`
inp2=`cat param |grep "$ip" |awk '{ print }'`
inp3=`cat param |grep "$ip" |awk '{ print }'`
inputfile=in
outputfile=out
rm -fr $inputfile
rm -fr $outputfile
mknod $inputfile p
touch $outputfile
#file description 7 for out and 8 for in
exec 7<>$outputfile
exec 8<>$inputfile
telnet $ip <&8 >&7 &
sleep 1; echo $inp1 >> $inputfile
sleep 1; echo $inp2 >> $inputfile
sleep 1; echo $inp3 >> $inputfile
tail -f $outputfile &
while true
do
read str
if [[ $str = "quit" || $str = "exit" ]]
then echo $str >> $inputfile ; exit
else echo $str >> $inputfile
fi
done
#==================================
参数文件, 输入在出现正常提示符之前需要输入的所有内容, 用空格分开, 以ip地址或者hostname开头
#=====param============
localhost root password
#=====================