[Shell] 纯文本查看 复制代码 常用脚本备份
自动配置msmtp,使用mail发邮件
#!/bin/bash
SRC=/usr/local/src
cd $SRC
#install msmtp client
# if your want support TLS/SSL,install openssl-devel
# yum install -y openssl-devel //
wget [url=http://nchc.dl.sourceforge.net/p]http://nchc.dl.sourceforge.net/p[/url] ... smtp-1.4.28.tar.bz2
tar xjf msmtp-1.4.28.tar.bz2
cd msmtp-1.4.28
./configure --prefix=/usr/local/msmtp && make && make install
cd /usr/local/msmtp/
mkdir etc
echo 'account gmail
host smtp.gmail.com
from [url=mailto:reportonline@gmail.com]reportonline@gmail.com[/url]
auth on
tls on
tls_starttls on
tls_force_sslv3 on
tls_trust_file /usr/local/msmtp/etc/gmail.crt
user [url=mailto:reportonline@gmail.com]reportonline@gmail.com[/url]
password 1234567890
port 587
syslog off
logfile /tmp/msmtp.log
account default: gmail' > /usr/local/msmtp/etc/msmtprc
wget -O /usr/local/msmtp/etc/gmail.crt [url=http://www.geotrust.com/resource]http://www.geotrust.com/resource[/url] ... ate%20Authority.crt
ln -s /usr/local/msmtp/bin/msmtp /usr/bin/
echo "set sendmail=/usr/bin/msmtp" >> /etc/mail.rc
脚本2 <监控mysql服务器主从,来自抚琴煮酒>
#!/bin/bash
#check MySQL_Slave Status
#crontab time every 10 min
test -e /data0/mysql/check_mysql_slave.log || touch /data0/mysql/check_mysql_slave.log
chown mysql.mysql /data0/mysql/check_mysql_slave.log
MYSQLPORT=`netstat -na|grep "LISTEN"|grep "3306"|awk -F[:" "]+ '{print $5}'`
MYSQLIP=`ifconfig eth0|grep "inet addr" | awk -F[:" "]+ '{print $4}'`
STATUS=$(/usr/local/mysql/bin/mysql -uadmin -ppassword -S /tmp/mysql.sock -e "show slave status\G" | grep -i "running")
IO_env=`echo $STATUS | grep IO | awk ' {print $2}'`
SQL_env=`echo $STATUS | grep SQL | awk '{print $2}'`
DATA=`date +"%y-%m-%d %H:%M:%S"`
if [ "$MYSQLPORT" == "3306" ]
then
echo "mysql is running"
else
mail -s "ERROR!server: $MYSQLIP mysql is down" [url=mailto:start@gmail.com]start@gmail.com[/url] -c [url=mailto:user1@gmail.com]user1@gmail.com[/url] -c [url=mailto:user2@gmail.com]user2@gmail.com[/url] -c [url=mailto:user3@gmail.com]user3@gmail.com[/url]
fi
if [ "$IO_env" = "Yes" -a "$SQL_env" = "Yes" ]
then
echo "Slave is running!"
else
echo "####### $DATA #########">> /data0/mysql/check_mysql_slave.log
echo "Slave is not running!" >> /data0/mysql/check_mysql_slave.log
echo "Slave is not running!" | mail -s "ERROR! $MYSQLIP MySQL Slave is not running" [url=mailto:start@gmail.com]start@gmail.com[/url] -c [url=mailto:user1@gmail.com]user1@gmail.com[/url] -c [url=mailto:user2@gmail.com]user2@gmail.com[/url] -c [url=mailto:user3@gmail.com]user3@gmail.com[/url]
fi ~
|