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 帐号 密码 节点  盘路径 本地路径  

  

上一篇:转载:C# 使用IP端口网络打印图片


下一篇:elementui滑块开启和关闭状态动态绑定