telnet自动登录并执行任务

来源:互联网 发布:编程语言 难度 编辑:程序博客网 时间:2024/05/21 08:04

autotelnet.sh可以通过建立管道的方式,实现自动登录,并自动从tftp服务器下载测试驱动模块进行替换,最后自动退出回到登录之前的状态。

#autotelnet.sh#!/bin/bashif (( $# != 2 ))then  echo " usage: $0 remote_ip tftp_ip "  exit 1fiip=$1inp1="root"inp2="password"inp3=""inp4="tftp -g -l helloworld.ko -r hellworld.ko $2"inp5="mv /lib/modules/2.6.18/kernel/char/hellworld.ko /lib/modules/2.6.18/kernel/char/hellworld.ko.bak"inp6="cp -vf hellworld.ko /lib/modules/2.6.18/kernel/char/hellworld.ko"inp7="rm -vf /root/hellworld.ko"inp8="exit"inp9=""inputfile=inoutputfile=outrm -fr $inputfilerm -fr $outputfilemknod $inputfile ptouch $outputfile#file description 7 for out and 8 for inexec 7<>$outputfileexec 8<>$inputfiletelnet $ip <&8 >&7 &sleep 1; echo $inp1 >> $inputfilesleep 1; echo $inp2 >> $inputfileecho $inp3 >> $inputfileecho $inp4 >> $inputfileecho $inp5 >> $inputfileecho $inp6 >> $inputfileecho $inp7 >> $inputfiletail -f $outputfile &sleep 1; echo $inp8 >> $inputfileecho "Bingo!!! Auto update test driver success!"
0 0
原创粉丝点击