shell脚本 ,在linux 下运行一个shell脚本登陆远程unix 服务器,请问这个脚本如何写?

shell脚本 ,在linux 下运行一个shell脚本登陆远程unix 服务器,请问这个脚本如何写?,第1张

#!/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=outlog
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


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/10914670.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-12
下一篇 2023-05-12

发表评论

登录后才能评论

评论列表(0条)

保存