rsync 本地路径到挂盘路径 ;挂盘路径到本地
作者:互联网
要解决的是每次都要输入密码,所以不能后台投递任务。
解决方案:
核心是expect
spawn
#!/usr/bin/expect -f set timeout 10 set username [lindex $argv 0] set password [lindex $argv 1] set host [lindex $argv 2] set src_file [lindex $argv 3] set dest_file [lindex $argv 4] spawn rsync -avtp $src_file $username@$host:$dest_file expect { "(yes/no)?" { send "yes\n" expect "*assword" { send "$password\n"} } "*assword" { send "$password\n" } } expect "100%" expect eof
#!/usr/bin/expect -f set timeout 10 set username [lindex $argv 0] set password [lindex $argv 1] set host [lindex $argv 2] set src_file [lindex $argv 3] set dest_file [lindex $argv 4] spawn rsync -avtp $username@$host:$src_file $dest_file expect { "(yes/no)?" { send "yes\n" expect "*assword" { send "$password\n"} } "*assword" { send "$password\n" } } expect "100%" expect eof
用法:
/home/lizhichao/local_remote.vpn 帐号 密码 节点 本地路径 挂盘路径
/home/lizhichao/remote_local.vpn 帐号 密码 节点 盘路径 本地路径
标签:file,set,lindex,路径,argv,expect,本地,挂盘,send 来源: https://www.cnblogs.com/koujiaodahan/p/15843107.html