定时推送mysql备份至备份中心,通过expect来实现,结果在执行脚本的时候报错
问题一
./scp_to_bkcenter.sh "wish_2015-06-07.sql"
-bash: ./scp_to_bkcenter.sh: /usr/expect/bin/expect: bad interpreter: No such file or directory
由提示可知/usr/expect/bin/expect不存在,表明没有安装expect
安装参考:http://www.cnblogs.com/daojian/archive/2012/10/10/2718390.html
问题二
在备份过程中,需要把文件名称作为输入的位置参数来引用
# ./scp_to_bkcenter_bak.sh "portal_112.74.78.64_2015-06-12.sql"
can't read "1": no such variable
while executing
"spawn scp /mnt/backup/$1 61.233.75.34:/home/mysql_bk_center/"
(file "./scp_to_bkcenter_bak.sh" line 3)
问题来了不识别位置参数
# cat scp_to_bkcenter.sh
#!/usr/expect/bin/expect -f
set file_name [lindex $argv 0] --需要这么来引用
spawn scp /mnt/backup/$file_name 111.111.1.11:/home/mysql_bk_center/
expect "111.111.1.11's password:"
sleep 10
send "1234567\r"
interact
阅读(3185) | 评论(0) | 转发(1) |