使用expect telnet 到远程服务器并在服务器上执行一些命令

来源:互联网 发布:孙宏斌和柳传志 知乎 编辑:程序博客网 时间:2024/04/28 17:14

telnet.sh

#!/usr/bin/expectexpec << EOFspawn telnet 182.119.xxx.xxxexpect "login:"send "your username\r"expect "Password:"send "your password\r"expect "$"send "#!/bin/ksh\r"expect "$"send "cd testfolder\r"expect "$"send "touch t.txt\r"expect "$"send "exit\r"


./telnet.sh运行
注意telnet.sh要有执行权限
\r没有这个就需要手动回车,不然会一直等着
在执行这个脚本的时候,还可以在本机进行其他操作,相互不影响
0 0
原创粉丝点击