-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpstop.sh
63 lines (46 loc) · 994 Bytes
/
pstop.sh
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
#!/bin/bash
LC_ALL=C
s=false
u=false
plik=""
cmd="sort -k 3 -n -r"
while getopts ":f:sumcn" opt
do
case $opt in
f) plik=$(< $OPTARG);;
s) s=true ;;
u) u=true ;;
m) cmd="sort -n -k 4 -r" ;;
c) cmd="sort -n -k 2 -r" ;;
n) cmd="sort -k 1" ;;
*) echo "Blad" ;;
esac
done
shift $((OPTIND-1))
# echo "s=$s u=$u m=$m c=$c n=$n plik=$plik"
if [ -z "$plik" ]
then
plik=$(ps -eo user,uid,pmem,pcpu,comm)
fi
plik=$(sed 1d <<< "${plik}")
declare -A liczba
declare -A pcpu
declare -A pmem
while read user uid mem cpu comm
do
if $s && [ $uid -ge 1000 ]
then
continue
fi
if $u && [ $uid -lt 1000 ]
then
continue
fi
let liczba[$user]++
pcpu[$user]=$(echo "$cpu + ${pcpu[$user]-0.0}" | bc -l )
pmem[$user]=$(echo "$mem + ${pmem[$user]-0.0}" | bc -l )
done <<< "${plik}"
for user in ${!liczba[*]}
do
printf "%-15s %5d %5.1f %5.1f\n" $user ${liczba[$user]} ${pcpu[$user]} ${pmem[$user]}
done | $cmd