I have a handmade NAS running on "Debian 10 buster" with RAID 5 in it,
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
And I tried to set up a notification about changing the RAID status, i was created a script with the following content:
#!/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
It runs without any problems as expected from shell, but when i run it from cronjob root gets this email for each execution.
/root/raid_status_monitor/raid_status.sh: line 4: mdadm: command not found
cronjob looks like this
root@fox-nas:~# crontab -l | grep -v "#" | grep raid
@hourly bash /root/raid_status_monitor/raid_status.sh
Can anyone help me to find out why is this happening?
Make sure you have mdadm and curl commands inside folders included in crontab's defined $PATH variable.
Also you can check where are these commands to use their full path in your script:
which mdadm curl