【crontab】
#每天6:00 执行a.sh
00 6 * * * /bin/sh /home/work/rxShell/a.sh
#每天3:20 执行a1.sh
20 3 * * * /bin/sh /home/work/rxShell/a1.sh
#每隔10分钟 执行b.sh
*/10 * * * * /bin/sh /home/work/rxShell/b.sh
#每隔60分钟 执行c.sh
*/60 * * * * /bin/sh /home/work/rxShell/c.sh
#x:50 执行 d.sh
50 0,7,8,9,10,11,12,14,15,16,17,18,19,20,21,22,23 * * * /bin/sh /home/work/rxShell/d.sh
【备份数据库】
cd ~/backdb/
#定义文件名
before_filename="qgzs.sql"
after_filename="qgzs_`date +%Y_%m_%d`.tar.gz"
#备份导出数据库
/usr/local/mysql/bin/mysqldump -h localhost -uroot -proot qgzs > ${before_filename}
#tar压缩打包
tar zcvf ${after_filename} ${before_filename}
#删除备份前的文件
rm -rf ${before_filename}
cd ~/backdb/temp_table/
#自定义输入要导出的表名
echo "Please Enter table name:"
read tbname
#定义文件名
before_filename="${tbname}.sql"
after_filename="${tbname}_`date +%Y_%m_%d`.tar.gz"
#备份导出数据库
/usr/local/mysql/bin/mysqldump -h localhost -uroot -proot qgzs $tbname > ${before_filename}
#tar压缩打包
tar zcvf ${after_filename} ${before_filename}
#删除备份前的文件
rm -rf ${before_filename}
【本地无需每次登陆操作远程服务器】
#!/usr/bin/expect -f
set ip 192.168.1.201
set password meimiao1905
set timeout 10
spawn ssh root@$ip
expect {
"*yes/no" { send "yes
"; exp_continue}
"*password:" { send "$password
" }
}
expect "#*"
send "cd pub.sh
"
interact