几个脚本

2020-07-28 15:14:52 浏览数 (1)

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

Tomcat 监控脚本
代码语言:javascript复制
#!/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 数据库定时备份
代码语言:javascript复制
#!/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 人点赞