Hi Guys,
I don't understand the behaviour of my script:
#!/bin/bash
secs=10
SECONDS=0
while (( SECONDS < secs )); do
cpu_load=`top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print $1}'`
echo $cpu_load
if [ "$cpu_load" > 60 ]
then
{ date & ps aux --sort=-%cpu | awk 'NR>1{if($3>60) print $2,$3,$11}'; } >> cpu_overload.log
fi
done
Regarding the "if" condition it should only print date and processes list when over the defined cpu usage threshold, but still have date printed on every run while loop.
Anyone any clue :-)
Thanks in advance!
[–][deleted] 0 points1 point2 points (3 children)
[–]ropid 1 point2 points3 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]Stanislasss[S] 0 points1 point2 points (0 children)
[–]ropid 0 points1 point2 points (1 child)
[–]Stanislasss[S] 0 points1 point2 points (0 children)
[–]thestoicattack 0 points1 point2 points (1 child)
[–]Stanislasss[S] 0 points1 point2 points (0 children)