mountAndFstab
zabbix 监控脚本,自动监测mount点挂载情况,若 /etc/fstab 中有未挂载的,先发告警信息,然后自动修复挂载。
本地盘一般会自动挂载,nas 重启后不会自动挂载。当然解决自动挂载的方法有很多,使用autofs也是个好主意,但要因地制宜,不同时期采用不同策略。
[code lang=bash]
#!/bin/bash
# Created: 2018-04-24 09:39:50
# Updated: 2018-04-26 use filesystem type
# Version: 1.0.1
# Description: check mount point and /etc/fstab especially for nas
# If something wrong happens then auto fix it.
# mount: only root can use "–all" option
# zabbix is not run as root so it can not auto fix.
# bash not global variable??
# to subshell caused by pipeline, local variable
export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
# volumeList="wls|DS146020"
fileSystemType="ext4|xfs|nfs|glusterfs"
# by default the return status code is 200 error code is 110
statusCode=200
for mountPoint in $(grep -E "${fileSystemType}" /etc/fstab | grep -v ^# | awk '{print $2}'); do
if [ $(df -h | grep -cw "$mountPoint") -eq 0 ]; then
# <!–1. send monitor message –>
statusCode=110
# <!–2. mount the missing volume –>
sudo mount -a
fi
let i++
done
echo $statusCode
[/code]