一、expect脚本同步文件
编辑脚本文件
vim test4.expect
在文件中添加如下内容
#!/usr/bin/expect
set passwd "12345"
spawn rsync -av root@192.168.177.200:/tmp/12.txt /tmp/
expect {
"yes/no" { send "yes\r"}
"password:" { send "$passwd\r" }
}
expect eof
执行脚本之前需要加上权限
chmod a+x test4.expect
./test4.expect
二、 expect脚本指定host和要同步的文件
编辑脚本文件
vim test5.expect
在文件中添加如下内容