I have a cronjob installed (Ubuntu 16) that runs with the root user. So in
sudo crontab -e
I have the following entry:
10 5 * * mon /home/userA/raidchecker.sh
And the script raidchecker.sh
does this:
#!/bin/sh
mail=`which mail`
rec="[email protected] [email protected]"
now=$( date +%Y%m%d-%H%M-%S )
mdstat=$( cat /proc/mdstat )
details=$( /sbin/mdadm --detail /dev/md2 )
diskusg=$( df -kh )
disk1=$( smartctl -A /dev/sda | grep Realloc | grep Sector )
disk2=$( smartctl -A /dev/sdb | grep Realloc | grep Sector )
disk1f=$( smartctl -A /dev/sda )
disk2f=$( smartctl -A /dev/sdb )
buddyinfo=$( cat /proc/buddyinfo | grep Normal )
echo "Check from $now\n\n=================\nMemory Fragmentation:\n$buddyinfo\n\nAll partitions:\n\n$mdstat\n\n=================\nData Partition:\n\n$details\n\n=================\nDisk Usage:\n$diskusg\n\n=================\nSMARTCTL:\n\nData Disk /dev/sda and sdb:\n$disk1\n$disk2\n\nFull Reports:\nDisk1:\n$disk1f\n\nDisk2:\n$disk2f" | $mail -s "Check from $now" $rec
When I execute the script manually from the shell ./raidchecker.sh
the email contains all infos as expected.
When the cronjob executes the script, the parameters disk1, disk2, disk1f and disk2f are empty (do not contain any data).
Why?