-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewinfo
More file actions
75 lines (70 loc) · 1.47 KB
/
viewinfo
File metadata and controls
75 lines (70 loc) · 1.47 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
function howto {
echo "-----------------------------"
echo "+ USAGE: viewinfo [-i cpu|mem] [-n NUM]"
echo "+ INFOS: show top NUM processes with the most CPU or memory usage in descent order"
echo "+ PARAM:"
echo " -i, cpu|mem, the item info to view, only support cpu or memory,default cpu"
echo " -n, NUM, the number of processes to view, default 10"
echo " -m, minimum, the minimum user-id,default 1000"
echo " -M, maximum, the maximum user-id,default 60000"
echo " -h, show this help information"
exit
}
m=1000
M=60000
I=4
N=10
while getopts "i:n:m:M:h" option
do
case "${option}" in
i)
case "${OPTARG}" in
"cpu"|"CPU"|"Cpu")
I=4
;;
"mem"|"MEM"|"memory")
I=5
;;
*)
howto
;;
esac
;;
n)
if [[ ${OPTARG} =~ ^[1-9][0-9]*$ ]]; then
N=${OPTARG}
else
howto
fi
;;
m)
if [[ ${OPTARG} =~ ^[1-9][0-9]*$ ]]; then
m=${OPTARG}
else
howto
fi
;;
M)
if [[ ${OPTARG} =~ ^[1-9][0-9]*$ ]]; then
M=${OPTARG}
else
howto
fi
;;
h)
howto
;;
*)
howto
;;
esac
done
usrs=$(getent passwd | awk -F':' -v "min=$m" -v "max=$M" '{ if ( ($3 >= min && $3 <= max && $7 != "/sbin/nologin")) print $1 }' | sort -u | xargs | sed 's/ /,/g')
# echo $usrs
# echo $m
# echo $M
# echo $I
# echo $N
ps -U mail -u mail -o ni,user,pid,pcpu,pmem,cputime,etime,comm | grep PID
ps -U $usrs -u $usrs -o ni,user,pid,pcpu,pmem,cputime,etime,comm | grep -v PID | sort -rn -k +${I} | head -${N}