bash - mdadm 状态改变警报脚本
问题描述
我有一个手工制作的 NAS,运行在“Debian 10 buster”上,里面有 RAID 5,
root@fox-nas:~# uname -a
Linux fox-nas 4.19.0-8-amd64 #1 SMP Debian 4.19.98-1 (2020-01-26) x86_64 GNU/Linux
我尝试设置有关更改 RAID 状态的通知,我创建了一个包含以下内容的脚本:
#!/bin/bash
wirepusher_id="your_id_here"
sr="/root/raid_status_monitor" #script_root
m_d="/dev/md0" #monitored_device
n_s=$(mdadm --detail "$m_d" | awk '/^State/ {printf "%s: ", $1}; /State / {print $NF}')
s_f=""$sr"/status.txt" #status_file
if [ ! -f "$s_f" ]; then
mdadm --detail "$m_d" > "$s_f"
else
o_f=$(awk '/^State/ {printf "%s: ", $1}; /State / {print $NF}' "$s_f")
fi
if [ "$n_s" != "$o_f" ]; then
echo "RAID status changed"
mdadm --detail "$m_d" > "$s_f"
echo "$o_f" | tee "$sr"/raid.log
curl -s "https://wirepusher.com/send?id=$wirepusher_id&title=$HOSTNAME $(hostname -I) $(curl -s 2ip.ru)&message=State of $m_d changed old $o_f new $n_s&type=RAID ALERT" -X POST
fi
它运行时没有任何问题,如 shell 预期的那样,但是当我从 cronjob root 运行它时,每次执行都会收到这封电子邮件。
/root/raid_status_monitor/raid_status.sh: line 4: mdadm: command not found
cronjob 看起来像这样
root@fox-nas:~# crontab -l | grep -v "#" | grep raid
@hourly bash /root/raid_status_monitor/raid_status.sh
谁能帮我找出为什么会这样?
解决方案
确保在 crontab 定义的 $PATH 变量中包含的文件夹中有 mdadm 和 curl 命令。
您还可以检查这些命令在哪里使用它们在脚本中的完整路径:
which mdadm curl
推荐阅读
- r - 如果您有打开的副本,如何将意外删除的数据保存到 Rstudio 环境中?
- jquery - 无法从 typeahead.js 中的 api 获得确切结果
- boto3 - 无法连接到端点 URL:“https://api.pricing.us-west-2.amazonaws.com/”
- gradle - 如何在两台 PC 之间复制 gradle 依赖项?
- android - 在 Android 上为数百名用户注册指纹并将他们同步到主服务器
- java - javax.ws.rs.client.Client 和 org.apache.cxf.jaxrs.client.WebClient 有什么区别
- firebase - docker 容器中的 Firebase 服务适用于功能,但不适用于托管
- c# - 处理 IScheduler.Scheduler 结果
- azure-devops - 能否在 PR 开始后添加更多必需的审阅者?
- java - Maven 测试:在 Jenkins 构建期间为一些测试类签出其他存储库