當前位置:編程學習大全網 - 編程軟體 - shell腳本 ,在linux 下運行壹個shell腳本登陸遠程unix 服務器,請問這個腳本如何寫?

shell腳本 ,在linux 下運行壹個shell腳本登陸遠程unix 服務器,請問這個腳本如何寫?

#!/bin/bash

tmptty=`tty`

tmptty=`basename $tmptty`

tmpname=`whoami`

ip="xxx" #目標主機地址

inp1="xxx^M" #主機的用戶名,,註意必須有^M

inp2="xxx^M" #主機的密碼,註意必須有^M

inp3="ls^M"

inp4="pwd^M"

inputfile=in

outputfile=out.log

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 2; echo $inp1 >> $inputfile

sleep 2; echo $inp2 >> $inputfile

sleep 2; echo $inp3 >> $inputfile

sleep 2; echo $inp4 >> $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

ps -ef | grep telnet | grep -v grep | grep -v telnetd | grep $tmptty | grep $tmpname | awk '{print " kill -9", $2}' | sh

ps -ef | grep tail | grep -v grep | grep -v telnetd | grep $tmptty | grep $tmpname | awk '{print " kill -9", $2}' | sh

  • 上一篇:vb和vb.net的區別和特點
  • 下一篇:倉頡語言編程在哪裏?
  • copyright 2024編程學習大全網