telnet.sh
#!/usr/bin/expect
expec << EOF
spawn telnet 182.119.xxx.xxx
expect "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要有执行权限
\r没有这个就需要手动回车,不然会一直等着
在执行这个脚本的时候,还可以在本机进行其他操作,相互不影响