运维中shell常⽤脚本shell最简单脚本
脚本1:监控服务邮件告警 #!/bin/bash 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 .\033[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 " romatic99@qq< 1waring"romatic99@qq<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 / BACKP A TH/MYSQLDB.sql if [ $? -eq 0 ];then echo
"\033[32mThe $MYSQLDB successfully " else echo "\033[32mThe mysql backup $MYSQLDB failed ,please checked " fi
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论