创建shell脚本topjui_source.exp,内容如下:
#!/usr/bin/expect spawn echo "###### running... ######" spawn echo $argv0 spawn echo $argv1 set timeout 30 spawn mysql -uroot -p123456 set timeout 30 expect { "hi" { send "You said hi "} "hello" { send "Hello yourself "} "bye" { send "That was unexpected "} "mysql>" { send "use demo_topjui_com "} } expect { #"mysql>" {send "source /home/backup/mysql/topjui/topjui.sql "} } expect "mysql>" send "exit " interact
加入到定时计划中,每5分钟自动还原一次topjui数据库:
*/5 * * * * /usr/bin/expect /home/shell/topjui_source.exp > /home/shell/log/topjui_source.log 2>&1