Chinaunix首页 | 论坛 | 博客
  • 博客访问: 372533
  • 博文数量: 80
  • 博客积分: 6032
  • 博客等级: 准将
  • 技术积分: 730
  • 用 户 组: 普通用户
  • 注册时间: 2005-07-05 20:07
文章分类

全部博文(80)

文章存档

2007年(1)

2006年(22)

2005年(57)

我的朋友

分类:

2005-11-11 14:22:09

自动输入用户名和密码用于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

#=====================

阅读(1371) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~