维护CentOS6.2下的一些常用脚本之二

原创 2012年03月22日 18:06:34

服务器监控的一些代码,备份,学习,待优化用#脚本


1,监控数据库的Processlist,超过5条不为空的记录则打印输出,CTRL+C退出

#/bin/sh
# usage:
# bash filename 

export MYSQLBIN=/usr/local/mysql/bin
export MYSQLHOST='localhost'
export MYSQLPORT=3336
export MYSQLUSER=root
export MYSQLPSWD='********'
export TMPFILE=/tmp/mysqlstatus.dump.txt
export ty=20

echo ■■■■■■ ${MYSQLBIN}/mysql  》FOR Show Processlist ※※※※※※※※※※※※※※※※※※※※

while [ "1" -eq "1" ]
do

        export CURRENTTIME=`date +%T`

        echo START------------ $CURRENTTIME >$TMPFILE

        $MYSQLBIN/mysql -u$MYSQLUSER -p$MYSQLPSWD \
            --host $MYSQLHOST -P$MYSQLPORT \
            -e "show processlist" >> $TMPFILE

         sed -i -e '/NULL/d' $TMPFILE

        export LINES=`wc -l $TMPFILE | awk '{print $1}'`

        LINES=$[LINES -2]
        echo END-------------- $LINES >>$TMPFILE
        echo  >>$TMPFILE

        if [ "$LINES" -gt "5" ]
        then
                cat $TMPFILE
        else
                ty=$[ty+1]

                if [ "$ty" -gt "20" ]
                then
                        export ty=0
                        echo
                        echo -n "$CURRENTTIME : "
                fi

                echo -n "$LINES | "

                sleep 3
        fi


        sleep 3

done


#2,清除QMAIL的邮件队列,不清楚为啥加入任务计划就不执行,手动执行又没问题。其中grep -v fix_qmail是排除自身的文件名:

####################################################
#            Clear Qmail's queue
#
#                        --Ecen.thq 2011.11.02
####################################################
#!/bin/bash
clear
echo
echo clear mail queue
echo ===============================================
echo `date +%Y/%m/%d-%H:%M:%S`
echo
/etc/init.d/igenus-qmail stop

ps aux|grep qmail|grep -v fix_qmail|awk '{print $2}'|xargs kill -9

mv /var/qmail/queue /var/qmail/queue_bak`date "+%m%d"`

mkdir /var/qmail/queue

/var/qmail/bin/queue-fix /var/qmail/queue

/etc/init.d/igenus-qmail start

echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ps -aef|grep qmail
echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ " ps -aef|grep qmail "

echo  `date +%Y/%m/%d-%H:%M:%S` >> qmail_fix.log

echo
echo =================over=================

#3,mysql每日备份的脚本

#!/bin/sh
# mysql_backup.sh: backup mysql databases and keep newest 5 days backup.
#
# ----------------------------------------------------------------------

# your mysql login information
# db_user is mysql username
# db_passwd is mysql password
# db_host is mysql host
# -----------------------------
db_user="root"
db_passwd="********"
db_host="localhost"

# the directory for story your backup file.
backup_dir="/backup/mysql/"

# date format for backup file (dd-mm-yyyy)
time="$(date +"%M-%H-%d-%m-%Y")"

# mysql, mysqldump and some other bin's path
MYSQL="mysql"
MYSQLDUMP="mysqldump"
MKDIR="mkdir"
RM="rm"
MV="mv"
GZIP="gzip"

# check the directory for store backup is writeable
test ! -w $backup_dir && echo "Error: $backup_dir is un-writeable." && exit 0


# the directory for story the newest backup
test ! -d "$backup_dir/backup.0/" && $MKDIR "$backup_dir/backup.0/"


# get all databases
all_db="$($MYSQL -u $db_user -h $db_host -p$db_passwd -Bse 'show databases')"


for db in $all_db
do
        $MYSQLDUMP -u $db_user -h $db_host -p$db_passwd $db | $GZIP -9 > "$backup_dir/backup.0/$time.$db.gz"
done


# delete the oldest backup
test -d "$backup_dir/backup.5/" && $RM -rf "$backup_dir/backup.5"


# rotate backup directory
for int in 4 3 2 1 0
do
        if(test -d "$backup_dir"/backup."$int")
        then
                next_int=`expr $int + 1`
                $MV "$backup_dir"/backup."$int" "$backup_dir"/backup."$next_int"
        fi
done


exit 0;



版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

CentOS6.2下配置foreman1.0

CentOS6.2下源码安装openStack glance

参考文档: http://glance.openstack.org/controllingservers.html http://glance.openstack.org/configuring....

解决CentOS 6.2下安装ipvsadm-1.26报错

解决CentOS 6.2下安装ipvsadm-1.26报错 阅读:466次   时间:2012-03-23 09:33:09   字体:[大 中 小] 最近研究一下LVS+Keepalived,...

CentOS6.2下安装eclipse

在eclipse官网下载eclipse的linux版本(此处省略下载过程),我下载的是eclipse-jee-indigo-SR2-linux-gtk.tar.gz,下面是安装过程:   1.sud...

CentOS6.2下配置KeepLived + LVS

网上看了许多例子,都有些小毛病,小笔误导致不能配置成功,我再REMIX一版希望对后来者有帮助。 LVS:软负载均衡软件,在网络7层中第4层进行转发,效率很高 KeepLived...

CentOS6.2下一步一步源代码安装OpenStack

5月3日,添加安装计算节点的说明(蓝色字体) OpenStack的essex正式版终于发布了,但是要想在CentOS下通过yum安装估计还得等上一段时间,因此不妨我们来一起通过源代码安装Op...

Centos6.2下LAMP环境的搭建

完全用源码安装的LAMP环境的搭建

应用体验 CentOS 6.2下搭建Web服务器(apache+mysql+php)

CentOS是企业Linux发行版领头羊Red Hat Enterprise Linux(以下称之为RHEL)的再编译版本,RHEL是很多企业采用的linux发行版本,需要向RedHat付费才可以使用...

CentOS6.2下一步一步源代码安装OpenStack(四)glance配置、运行、测试

本文与前面所写的一篇关于glance的安装配置文章大部分是重复的,如果已经看过前面的那一篇,此篇略读即可 1.配置 1.1拷贝默认配置文件: [ugyn@cc keystone-2012.1]$...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)