Search code examples
linuxbashcronubuntu-servermdadm

no mdadm -D output in crontab


I have the following script:

#!/bin/bash
# wait, just in case hdd md0 in not mountet yet    
sleep 30 
# write Raid state in log-file
mdadm -D /dev/md0 > /home/main_usr/myScripts/raidHealth.log
#just check if it writes to the file
echo "just a Test" >> /home/main_usr/myScripts/raidHealth.log  

I´ve done the following things: 1. made file executable 2. changed owner to root 3. wrote script into crontab (sudo crontab -e | @reboot /home/main_usr/myScripts/checkRaid.sh)

So heres my Problem: When I run the script, everything works just perfect. But when I reboot my Computer the script runs, but my .log file just contains "just a Test". No output of the mdadm-command. I can´t explain why the mdadm-command is empty in this case. Maybe someone can help me out.

I also should mention that I need sudo to run the script (mdadm-command)


Solution

  • Thanks for your help.

    The Problem was that the crontab -e section could´nt find the mdadm command (I thing it is a path issue).

    So here´s how I fixed it in another way:

    • moved my script to /usr/local/sbin/checkRaid.sh
    • don´t used crontab -e but instead used /etc/crontab file and entered there

      */10 * * * * root /usr/local/sbin/checkRaid.sh

    In normal words: every 10 Minutes run my script as root. It worked perfectly without any Path issues of the mdadm-command.