运维中shell常用脚本

脚本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 < Server monitior*****
通知类型 :故障
服务; 1 主 机 : 1 主机: 1M_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"romatic99@qq.com<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 MYSQLCMDuMYSQLUSR -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

你可能感兴趣的:(面试总结,Linux运维,运维面试)