- 论坛徽章:
- 0
|
http://bbs.chinaunix.net/viewthread.php?tid=201364
panlm写的一个自动telnet登录脚本,我还是不太明白如下几条代码,请各位帮忙解释一下,谢谢!
------------疑惑部分 Begen--------------
1、inputfile=in
outputfile=out
这两条代码的作用是什么呢,是将当前目录下的文件in和out赋给inputfile和outputfile,还是给inputfile和outputfile变量赋赋值?
我的理解是给变量赋值,但是如果是赋值,该语句就没有必要了,应为可直接将mknod $inputfile p该写为mknod in p,将touch $outputfile该写为touch out
2、telnet $ip <&8 >&7 &
我的理解是从$inputfile对应的文件输入,并将正确输出重定向到$outputfile,而事实上$inputfile为空。
3、sleep 1; echo $inp1 >> $inputfile
sleep 1; echo $inp2 >> $inputfile
sleep 1; echo $inp3 >> $inputfile
这3条代码应该将所有标准输出追加到$inputfile中,而本脚本中$inputfile应该是输入文件
4、tail -f $outputfile &
从脚本来看$outputfile始终为空,这样能看到什么呢
5、touch $outputfile
这条代码应该可以不要,因为exec 7<>$outputfile语句会自动创建
------------疑惑部分 end----------------
------------panlm的原始脚本-------------
自动输入用户名和密码用于tenlnet的shell, 哈哈
用linux的朋友且经常用配置路由器的可有福了. 
今天刚刚完成, 大家多提意见 
#===========autotelnet.sh==============
#!/bin/bash
if (( $# != 1 ))
then
echo " usage: $0 address "
exit 1
fi
ip=$1
inp1=`cat param |grep "$ip" |awk '{ print $2 }'`
inp2=`cat param |grep "$ip" |awk '{ print $3 }'`
inp3=`cat param |grep "$ip" |awk '{ print $4 }'`
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
#=====================
[ 本帖最后由 cuxxx 于 2007-6-25 00:49 编辑 ] |
|