0

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?

asked Mar 3, 2020 at 7:39

1 Answer 1

0

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
answered Mar 3, 2020 at 8:00
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.