免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1487 | 回复: 1
打印 上一主题 下一主题

仍然是自动telnet的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-06-25 00:44 |只看该作者 |倒序浏览
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 编辑 ]

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
2 [报告]
发表于 2007-06-25 08:55 |只看该作者
1.有没有必要根据个人需要和程序书写习惯,没什么可以讨论的
2.如果$inputfile为空,telnet会一直等着从管道读数据或等管道关闭
3.一个文件可以作为一个程序的输入,为什么不可以同时作为其它程序的输出?
4.请参2
5.请参1
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP