几个脚本

原创
2016/08/23 11:03
阅读数 376

都是在网上找到,然后自己整理了一下。

Tomcat 监控脚本

#!/usr/bin/env bash

##############################################################################
#                                                                                                                                                                 
# Tomcat monitor                                                                                                                                     
# 2016-08-16 lpe234                                                                                                                          
#
# monitor every 5 minutes                                                                                                                        
# crontab -e                                                                                                                                    
# */5 * * * * /root/scripts/monitor_tomcat.sh >> /root/scripts/monitor_tomcat.log 2>&1                       
# 
# chmod 700 /root/scripts/monitor_tomcat.sh                                                                     
##############################################################################

now=`date '+%Y-%m-%d %H:%M:%S'`

# define process name
process_names="tomcat_a tomcat_b"
ta_process_count=1

ta_process_number()
{
    ta_number=`ps aux | grep ${ta_process_name} | grep -v grep | wc -l`
    return ${ta_number}
}

for ta_process_name in ${process_names}
do
    ta_process_number
    ta_num=$?

    if [ ${ta_num} -lt ${ta_process_count} ]
    then
        echo "[$now] [ERROR] '$ta_process_name' process_number is $ta_num, restart it."
        # restart it
        sudo -u ${ta_process_name} sh /usr/${ta_process_name}/bin/startup.sh
#    else
#        echo "[$now] [DEBUG] '$ta_process_name' process_number is $ta_num, status ok."
    fi
done

MySQL 数据库定时备份

#!/usr/bin/env bash

#####################
# backup database && delete backup 7 days ago
#####################

# crontab -e
# 0  3  *  *  *  /root/scripts/backup_db.sh > /dev/null 2>&1


cd /mnt/sdc/db_back

# do backup
for DB_NAME in 'db-1' 'db-2'
do
    DB_FILE_NAME=${DB_NAME}-`date +%Y%m%d_%H%M%S`
    mysqldump -uroot ${DB_NAME} > ${DB_FILE_NAME}.sql
    tar -zcvf ${DB_FILE_NAME}.sql.tar.gz ${DB_FILE_NAME}.sql
    rm -rf ${DB_FILE_NAME}.sql
done

# delete old backup
find . -mtime +7 -exec rm -rf {} \;

展开阅读全文
打赏
0
1 收藏
分享
加载中
更多评论
打赏
0 评论
1 收藏
0
分享
返回顶部
顶部