load=`echo $(cat /proc/loadavg | awk '{print $1}') \> 8 | bc -l`
echo "SABRETOOTH! Your Server Load Alert Needs Attention! " | mail -s "System Load Alert $load" spectre@tlp.zapto.org
load=`echo $(cat /proc/loadavg | awk '{print $1}') \> 8 | bc -l`
echo "SABRETOOTH! Your Server Load Alert Needs Attention! " | mail -s "System Load Alert $load" spectre@tlp.zapto.org
Can anyone riddle me why the current load avg doesn't make it into the alert email? $load isn't printing... thats nominally all one line, its just wrapped at 80 cols here.
load=`echo $(cat /proc/loadavg | awk '{print $1}') \> 8 | bc -l`
if [ "$load" -ne 0 ]; then
load=`echo $(cat /proc/loadavg | awk '{print $1}') \> 8 | bc -l`
if [ "$load" -ne 0 ]; then
load=`echo $(cat /proc/loadavg | awk '{print $1}') \> 8 | bc -l`
if [ "$load" -ne 0 ]; then
This will make more sense, but I didn't realise what it was all doing at the time, and I left the logic operation out.
Somehow in a fashion I don't completely understand renders the question a binary one, 1 or 0, which is why the loadavg is never printed at least
not a way I recognised.
Looking at your logic, I would be guessing in some way the cat can still be removed and it was a foible of whoever wrote it. I tend to do it that way too, I'm more used to redirection than what individial commands can do.
I still don't quite get this though.
awk '{print $1}') \> 8
and how that becomes print if > 8..
and bc is rendering the integer.
In order to get what I was looking for, the actual load average into the message, I had to re-read "/proc/loadavg"
Thanks for your time, and explanation.
The shell can't do arbitrary numeric comparisons itself; it's kind of
dumb that way. But we CAN use the `expr` command, with the caveat that
if [ $(expr $load '>' 8) -eq 1 ]; then
The shell can't do arbitrary numeric comparisons itself; it's kind of dumb that way. But we CAN use the `expr` command, with the caveat tha
Depends on the shell..
if [ $(expr $load '>' 8) -eq 1 ]; then
This could be changed to
if [ $load -gt 8 ]; then ...
Sadly, no. `-gt` et al do integer comparisons, and don't understand fractional numbers like load averages:
This could be changed to if [ $load -gt 8 ]; then
kind ofThe shell can't do arbitrary numeric comparisons itself; it's
dumb that way. But we CAN use the `expr` command, with the
Sysop: | sneaky |
---|---|
Location: | Ashburton,NZ |
Users: | 31 |
Nodes: | 8 (0 / 8) |
Uptime: | 231:07:43 |
Calls: | 2,088 |
Calls today: | 2 |
Files: | 11,140 |
Messages: | 948,564 |