腳本1:監控服務郵件告警
#!/bin/bash
EMAIL=email.txt
echo -e "\033[32m \033[1m "
cot=
ps -ef | grep $1 | grep -v email |grep -v grep |wc -l
M_IPADDIR=
hostname -i
DATE=
date
if [ $cot -eq 0 ];then
cat > $EMAIL <<EOF
Server monitior*****
通知類型 :故障
服務; 1 主 機 : 1 主機: 1主機:M_IPADDIR
狀态:警告
日期:$DATE
CRITICAL - $1 Server Connec
EOF
#dos2unix $EMAIL
echo -e " \033[32mThe Monitor KaTeX parse error: Expected 'EOF', got '\0' at position 24: …,Please check .\̲0̲33[0m " | mail …M_IPADDIR 1 w a r i n g " r o m a t i c 99 @ q q . c o m < 1 waring " [email protected]< 1waring"[email protected]<EMAIL >>/dev/null 2&>1
else
echo “The $1 server is ok”
fi
腳本2:資料庫備份
#!/bin/bash
#mysql back_up
#by author sws
BACK_PATH=/data/backup /
date +%Y%m%d
MYSQLDB=ocdp
MYSQLUSR=root
MYSQLPW=sws
MYSQLCMD=/usr/bin/mysqldump
if [ $UID -ne 0 ];then
echo “pleae use user root”;
exit
fi
if [ -d $BACK_PATH];then
mkdir -p $BACK_PATH
echo " \033[32mThe $BACK_PATH create sucessfully "
else
echo “this $BACK_PATH is exist”
fi
M Y S Q L C M D − u MYSQLCMD -u MYSQLCMD−uMYSQLUSR -p$MYSQLPW -d $MYSQLDB > B A C K P A T H / BACK_PATH / BACKPATH/MYSQLDB.sql
if [ $? -eq 0 ];then
echo "\033[32mThe $MYSQLDB successfully "
else
echo "\033[32mThe mysql backup $MYSQLDB failed ,please checked "
fi