I’m going nuts over something seemingly simple.
I want to run a script every minute which reboots when it finds something in a log.
It simply does not run via cron.
My script in /home/root/resetiferror.sh
!/bin/bash
tail -fn0 /var/log/messages | while read line ; do
echo "${line}" | grep -i "failed to read" >> /var/log/resetiferror
if [ $? = 0 ] ; then
echo "$(date) found so restart" >> /var/log/resetiferror
/sbin/reboot
fi
done
This is my crontab:
1 * * * * timeout 5s /home/root/resetiferror.sh >> /var/log/resetiferror.log 2>&1
I made it executable
It DOES work with
/bin/sh -c "(export PATH=/usr/bin:/bin; /home/root/resetiferror.sh </dev/null >/dev/null 2>&1)"