expect 实现本地到远程的scp
expect文件demo 令文件名为test.exp
#!/usr/bin/expect -f set timeout -1 set pwd "123456" set src_file [lindex $argv 0] set dest_file [lindex $argv 1] spawn /usr/local/bin/./scp /data/softdb_userinfolog/test/$src_file user@ip:/data/home/txcp_aqgj/tmp/softdb_userinfo/test/$dest_file expect "Password:" send "$pwd\r" set timeout 300 expect { eof { exit 0;} }
针对不同的版本 这段代码会需要填写不同的指令
expect "Password:" send "$pwd\r"
Shell中调用
./test.exp 参数1 参数2