-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopoftop
executable file
·55 lines (48 loc) · 1.08 KB
/
topoftop
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
# Gets the heaviest job from top, if above certain threshold.
# Cpucsekk stuff first
if [ ! -d $HOME/.cpucsekk/ ]
then
mkdir $HOME/.cpucsekk/
fi
# Edit this file for different CPU load threshold.
if [ ! -f $HOME/.cpucsekk/cpucsekk.txt ]
then
echo "15" > $HOME/.cpucsekk/cpucsekk.txt
fi
# Don't display anything below this threshold:
cpupc=`cat $HOME/.cpucsekk/cpucsekk.txt`
re='^[0-9]+$'
if ! [[ $cpupc =~ $re ]] ; then
echo "$HOME/.cpucsekk/cpucsekk.txt should contain a single percentage number." >&2; exit 1
fi
# Get top percentage and name of process
topoutp=`top -b -n1 |
awk '{
# We set the relevant column numbers further down. If they are set then print from the next line and exit.
if (commcol>0){
printf "%d ",$cpucol
printf $commcol
exit
}
# Setting relevant column numbers here.
for (i=1; i<=NF; i++){
if ($i=="%CPU"){
cpucol=i
}
if ($i=="COMMAND"){
commcol=i
}
}
}'`
topp=${topoutp% *}
topn=${topoutp#* }
## Test:
#echo "$topoutp"
#echo "topp: $topp"
#echo "$topn"
#echo "cpupc: $cpupc"
if [[ $topp -gt $cpupc ]]
then
echo "$topn $topp%"
fi