Load server

Zabidin5584

Member
Joined
Mar 14, 2024
Messages
33
Reaction score
5
Credits
307
Hi,

Does this bash script working?
`
#!/bin/bash trigger=4.00
load=cat /proc/loadavg | awk '{print $1}' response=echo | awk -v T=$trigger -v L=$load 'BEGIN{if ( L > T){ print "greater"}}' if [[ $response = "greater" ]]
then sar -q | mail -s"High load on server - [ $load ]" [email protected] fi`

Thanks.
 


Moving to Command Line subforum, where scripting inquiries are dealt with.

Chris Turner
wizardfromoz
 
Hi,

Does this bash script working?
`
#!/bin/bash trigger=4.00
load=cat /proc/loadavg | awk '{print $1}' response=echo | awk -v T=$trigger -v L=$load 'BEGIN{if ( L > T){ print "greater"}}' if [[ $response = "greater" ]]
then sar -q | mail -s"High load on server - [ $load ]" [email protected] fi`

Thanks.
To get the script to work, I had to amend a few things as below, but it works :)
The mail line in the script I leave to your system since the mailer here is bit different so I've omitted it but there shouldn't be an issue if your mailer is configured to work.

Code:
#!/bin/bash

trigger=4.00

load="$(cat /proc/loadavg | awk '{print $1}')"

response="$(echo "$(awk -v T=$trigger -v L=$load 'BEGIN { if (L > T) {print "greater"}}')")"

if [[ $response = "greater" ]]
then
   sar -q
else
   echo less
fi
 
Top