[root@mongodb ~]# rpm -ivh tcl-8.5.7-6.el6.x86_64.rpm
warning: tcl-8.5.7-6.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
Preparing… ########################################### [100%]
1:tcl ########################################### [100%]
[root@mongodb ~]# rpm -ivh expect-5.44.1.15-5.el6_4.x86_64.rpm
warning: expect-5.44.1.15-5.el6_4.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing… ########################################### [100%]
1:expect ########################################### [100%]
实现脚本如下
[root@mongodb mongo]# more conn_sftp.sh
#!/usr/bin/expect
#!/bin/sh
set tim [lindex $argv 0]
set tnm [lindex $argv 1]
spawn sftp root@192.168.169.130
expect “password:”
send “root\n”
expect “sftp>”
send “get /mysql/*_$tim.$tnm\r”
send “exit\n”
interact
[root@mongodb mongo]# ./conn_sftp.sh 20150505 flg====>>>>这里需要注意不能用sh,要用.方式运行
spawn sftp root@192.168.169.130
Connecting to 192.168.169.130…
root@192.168.169.130’s password:
sftp> get /mysql/*_20150505.flg
File “/mysql/*_20150505.flg” not found.
sftp> exit