一、apache服务器监控
[root@localhost ~]
port=$(nmap -sT 192.168.114.135 | grep tcp | grep http | awk '{print $2'})
if [ "$port" == "open" ]
then
echo "$(date) httpd is running" >> /tmp/httpd-sendtry-acc.log
else
/etc/rc.d/init.d/httpd restart &> /dev/null
echo "$(date) httpd reboot!!" >> /tmp/httpd-sendtry-err.log
fi
二、数据库定时备份
[root@localhost sh]
BAK_DIR=/data/db-backup/$(date +%Y%m%d)
DB_NAME="webserver"
DB_USER="root"
DB_PWD="123456"
MYSQL_DUMP_CMD=/usr/bin/mysqldump
if [ $UID -ne 0 ];then
echo "请使用root用户执行";
exit;
fi
if [ ! -d $BAK_DIR ];then
mkdir -p $BAK_DIR
echo -e "$BAK_DIR 创建成功"
else
echo -e "$BAK_DIR 目录已存在"
fi
$MYSQL_DUMP_CMD -u$DB_USER -p$DB_PWD $DB_NAME > $BAK_DIR/$DB_NAME.sql
if [ $? -eq 0 ];then
echo -e "数据库备份成功"
else
echo -e "数据库备份失败,请检查备份脚本"
fi
exit