經過rsync的ssh差別備份方式同步本地目錄到遠端目錄,expect代碼以下,命令行手動執行便可javascript
Expect代碼 java
- # cat expecttool
- #!/usr/bin/expect -f
-
- set timeout 7200;
-
- spawn /usr/bin/rsync -avz -e "/usr/bin/ssh" /path/to/local/dir/ remoteuser@remotehost:/path/to/remote/dir/
- expect {
- "*yes/no*" {
- send "yes\r";
- exp_continue
- }
- "*assword*" {
- send "pasword\r";
- }
- }
- interact
若是要放到crontab任務中,須要把interact替換爲 app
expect eofssh
exitspa
這種方式在crontab和命令行都可運行命令行