就是一个自己写的脚本啦~~
用expect工具写脚本
题目:写一个expect脚本,模拟ftp 登录并下载文件shell_jobs.tar.gz
1、首先,下载ftp服务器,yum install ftp
2、创建以.exp结尾的文件,vim ftp.exp
3、代码如下:
#!/usr/bin/expect
2
3 set name "ftp"
4 set passwd ""
5 set host [lindex $argv 0]
6 set timeout 300
7 spawn ftp $host
8
9 expect {
10 "Name" {
11 send "$name\r"
12 exp_continue
13 }
14 "Password" {
15 send "$passwd\r"
16 exp_continue
17 }
18 ">" {
19 send "get shell_jobs.tar.gz\r"
20 }
21 }
22 expect eof