#!/bin/bash
hostname=`hostname`
for i in `df -h |sed -n '/\/$/p' |gawk '{ print $3 }' | sed 's/%//' |sed 's/G//'`
do
if [ $i -le 20 ]; then
echo "$hostname disk space<20G"
/bin/mail -s "$hostname space<20G" panxianpei@gmail.com
fi
done
服务器的负载监控
#!/bin/bash
N=10
load=`uptime |awk '{print $10}' |cut -d '.' -f 1`
if [ $load -gt $N ]
then
/bin/mail -s "84.22.112.86_load>$N%" 13528489494@139.com
fi
MYSQL 主从复制监控
#!/bin/bash
mysql -hlocalhost -uroot -p'1332' -e "show slave status\G;" |grep -i running >slave.log
if [ `cat slave.log|grep -i io |awk -F : '{ print $2 }'` != "Yes" ]
then
echo "slave io process is error"
/bin/mail -s "watch-movie5_slave_down" 13528489494@139.com fi
if [ `cat slave.log |grep -i sql |awk -F : '{ print $2 }'` != "Yes" ]
then
echo "slave sql process is error"
/bin/mail -s "watch-movie5_slave_down" 13528489494@139.comfi
数据库备份脚本
#!/bin/bash
#backup the db file
export time1=`date -d"today" +%Y-%m-%d`
mysqldump -uadmon_hulu -p'$W-w?' admon_anime > /home/backup_file/db_backup/admon_anime/admon_anime."$time1"
mysqldump -uadmon_hulu -p'$W-G?' admon_reality > /home/backup_file/db_backup/admon_reality/admon_reality."$time1"
mysqldump -uadmon_hulu -p'$W4w?' admon_hulu > /home/backup_file/db_backup/admon_hulu/admon_hulu."$time1"
#delete the log file of 10 days ago
export time2=`date -d"10 days ago" +%Y-%m-%d`
rm -f /home/backup_file/db_backup/admon_anime/admon_anime."$time2"
rm -f /home/backup_file/db_backup/admon_reality/admon_reality."$time2"
rm -f /home/backup_file/db_backup/admon_hulu/admon_hulu."$time2"
数据库备份然后上传的脚本
#!/bin/sh
IP=watch-movie5-84.22.112.86
#IP=sitemanager-174.36.172.101
scriptsDir=`pwd`
#dataDir=/usr/local/mysql/data
dataDir=/usr/local/mysql/var
tmpBackupDir=/tmp/mysqlblackup
backupDir=/backup/mysql
ftpUser=zlxbackup
ftpPWD='fDSLD'
mysqlPWD='dsadsf'
if [[ -e $tmpBackupDir ]]; then
rm -rf $tmpBackupDir/*
else
mkdir $tmpBackupDir
fi
file=`ls -t /backup/mysql|grep tar|sed -n '15,$p'`
for i in $file;do
rm -rf /backup/mysql/$i
done
if [[ ! -e $backupDir ]];then
mkdir -p $backupDir
fi
echo "`date +%Y%m%d%H%M` mysqlback start" >>"$backupDir"/`date +%Y%m%d`.log
dbname=`find "/usr/local/mysql/var" -type d|sed -e "s/\/usr\/local\/mysql\/var\///"|sed -e "s/\/usr\/local\/mysql\/var//"|sed -e "s/^test$//"|grep -v "mysql"|grep -v 2010|sed -e "/^$/d"`
for databases in $dbname; do
if [[ $databases == "" ]]; then
continue
else
errfile="$backupDir"/`date +%Y%m%d`.err
echo "dumping $databases">>$errfile
/usr/local/mysql/bin/mysqldump -uroot -p$mysqlPWD $databases >"$tmpBackupDir"/"$databases".sql 2>>$errfile
fi
done
echo "`date +%Y%m%d%H%M` mysqlback stop,start compress!" >>"$backupDir"/`date +%Y%m%d`.log
date=`date +%Y%m%d-%H%M`
cd $tmpBackupDir
tar czf $backupDir/mysql-$IP-$date.tar.gz ./
echo "`date +%Y%m%d%H%M` mysqlback end!" >>"$backupDir"/`date +%Y%m%d`.log
#End
date0=`date +%Y%m%d`
cd $backupDir
/usr/bin/ftp -n<open 67.228.150.197 21
user $ftpUser $ftpPWD
bin
#passive
mkdir -p $date0
cd $date0
put mysql-$IP-$date.tar.gz
bye
EOF
数据库备份的脚本
#!/bin/bash
#backup the db file
export time1=`date -d"today" +%Y-%m-%d`
#echo $time1
/usr/local/mysql/bin/mysqldump -u'watchmo3' -p'ACr>:4%' watchmo3_data > /home/backup_file/db_backup/watchmo3_data/watchmo3_data."$time1"
#delete the log file of 10 days ago
export time2=`date -d"10 days ago" +%Y-%m-%d`
#echo $time2
rm -f /home/backup_file/db_backup/watchmo3_data/watchmo3_data."$time2"
网站监控的脚本
#!/bin/bash
status1=`curl -I 2>/dev/null | grep HTTP |awk '{print $2}'`
sleep 10
status2=`curl -I 2>/dev/null | grep HTTP |awk '{print $2}'`
sleep 10
status3=`curl -I 2>/dev/null | grep HTTP |awk '{print $2}'`
sleep 10
line=`cat /var/script/movie1 | wc -l`
if [ "$status1" -eq 200 -a "$status2" -eq 200 -a "$status3" -eq 200 ];then
echo > /var/script/movie1
fi
if [ "$status1" != "200" -a "$status2" != "200" -a "$status3" != "200" -a "$line" -le 5 ];then
echo "#####################" >> /var/script/movie1
curl "" >/dev/null 2>&1
curl "" >/dev/null 2>&1
# curl "" >/dev/null 2>&1
fi
磁盘监控脚本
#!/bin/bash
for i in `df | grep /dev | awk '{print $5}' | sed 's/%//g'`
do
if [ $i -gt 98 ]; then
/bin/mail -s "watch-movie4_dist>98%" 13528489494@139.comfi
done
阅读(893) | 评论(1) | 转发(0) |