從centos服務器上將數據庫備份拷貝到本地
centosubuntu腳本備份數據庫
解決此問題要用到expect腳本:
寫法如下,注意一定要設置timeout長一點,否則考到一半就停止了:
#!/usr/bin/expect -f
set password ********
set date [exec date "+%Y%m%d"]
#download local host
spawn scp -r root@{IP地址}:/home/{ps-name}/backup/db/production$date.sql /root/db/
set timeout 3
expect {
"yes/no" {send "yes\r";exp_continue}
}
expect "root@{IP地址}'s password:"
set timeout 30
send "$password\r"
set timeout 3000
send "exit\r"
expect eof