and another to alert me when load average crosses 0.8 * number of CPUs, following this -
https://gist.github.com/santhoshvr/bd6db5b1cab4f8d181d2ac2b59dd08aa
https://gist.github.com/santhoshvr/bd6db5b1cab4f8d181d2ac2b59dd08aa
(need to install bc to get this to work - sudo apt install bc)
The disk space cron was working, but the load average cron would not work - it would work if run from the command-line when I tested by putting in a threshold like 0.01, but not in the cron.
Troubleshooting the cron with the techniques given here -
https://serverfault.com/questions/449651/why-is-my-crontab-not-working-and-how-can-i-troubleshoot-it
/var/log/cron
or
var/log/syslog
don't exist on this minimal install of Ubuntu 24.04.
Neither does /var/spool/mail/root - /var/spool/mail is empty.
So, trying to redirect errors to a log file with 2>&1
loadalert.sh > /path/to/loadalertcron.log 2>&1
That log file showed /path/to/loadalert.sh: 22: 1: not found
Turns out it was bash which was not being found, since the "if" command was triggering the "not found". In the first line, the #!/bin/bash had a missing ! - and the path to bash, found with
which bash
was actually /usr/bin/bash and not /bin/bash
which bash
was actually /usr/bin/bash and not /bin/bash
So, just changed the first line to
#!/usr/bin/bash
and the script started working fine in the cron job.
No comments:
Post a Comment