add some shell file

add some shell file
pull/6/head
KaliArch 2019-05-13 17:41:33 +08:00 committed by GitHub
parent 86e5e637ae
commit 51818521ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,32 @@
#!/bin/bash
hostname=`/bin/hostname`
week=`date +%w`
datadir=/backup
logdir=/backup/log
mycnf=/etc/my.cnf
Time=`date +%Y-%m-%d_%H-%M-%S`
cmd=`which innobackupex`
user=root
passwd=mysqladmin
function getdir()
{
if [ ! -d ${datadir} ];then
mkdir -p ${datadir}
fi
}
function backup()
{
if [ ${week} == "0" ];then
$cmd --defaults-file=${mycnf} --user=${user} --password=${passwd} ${datadir}&>${logdir}/${Time}-log
[ $? -eq 0 ] && stat=`tail -1 ${logdir}/${Time}-log |awk '{print $4}'`
if [ "${stat}" == "OK!" ];then
echo "${Time} mysql backup is success!"
else
echo "${Time} mysql backup is fail! please check ${logdir}/${Time}-log"
fi
else
$cmd --defaults-file=${mycnf} --user=${user} --password=${passwd} --incremental --incremental-basedir=${datadir}&>${logdir}/${Time}-log
}

View File

@ -0,0 +1,19 @@
#!/bin/bash
#mail xuel@51idc.com
#data 2017/2/23
#function: use iptables Brute force
SCAN=`/bin/egrep "Failed password for root" /var/log/secure|awk -F'[ :]+' '{print $13}'|sort|uniq -c|awk '{print $1"="$2;}'`
for I in ${SCAN}
do
SCANUM=`echo ${I}|awk -F'=' '{print $1}'`
SCANIP=`echo ${I}|awk -F'=' '{print $2}'`
if [ ${SCANUM} -gt 100 ] && [ -z "`/sbin/iptables -vnL INPUT | grep $SCANIP`" ];then
/sbin/iptables -I INPUT -s $SCANIP -m state --state NEW,RELATED,ESTABLISHED -j DROP
echo "`date` $SCANIP($SCANUM)">>/var/log/scanIP.log
fi
done
if [ $? -eq 0 ];then
service iptables save && service iptables restart
fi

View File

@ -0,0 +1,20 @@
#! /bin/bash
cat /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print $2"="$1;}' > /root/black/black.txt
DEFINE="5"
for i in `cat /root/black/black.txt`
do
IP=`echo $i |awk -F= '{print $1}'`
NUM=`echo $i|awk -F= '{print $2}'`
if [ $NUM -gt $DEFINE ]; then
grep $IP /etc/hosts.deny > /dev/null
if [ $? -gt 0 ]; then
echo "sshd:$IP" >> /etc/hosts.deny
fi
fi
done

View File

@ -0,0 +1,17 @@
#!/bin/bash
mysql_user='root'
mysql_pass="bhVd!564qazWSX78U#7"
data=$(/bin/date +%Y-%m-%d-%H:%M)
/bin/netstat -lntup|egrep ":3306"|grep -v grep>/dev/null0
if [ $? -eq 0 ];then
Slave_IO=`/data/mysql/bin/mysql -u${mysql_user} -p${mysql_pass} -e "show slave status\G"|grep "Slave_IO_Running:"|awk -F": " '{print $2}'`
Slave_SQL=`/data/mysql/bin/mysql -u${mysql_user} -p${mysql_pass} -e "show slave status\G"|grep "Slave_SQL_Running:"|awk -F": " '{print $2}'`
if [ "$Slave_IO" == "Yes" ] && [ "$Slave_SQL" == "Yes" ];then
STAT=1 && echo "$data mysql-status is ok">>/var/log/mysql-status.log
else
STAT=0 && echo "$data mysql-status is error">>/var/log/mysql-status.log
fi
else
STAT=0 && echo "$data mysql-status is error">>/var/log/mysql-status.log
fi
/usr/bin/zabbix_sender -z 101.227.67.205 -s "DaoDaEr-mysql-status" -k mysql -o $STAT