-
Notifications
You must be signed in to change notification settings - Fork 0
/
process
executable file
·51 lines (45 loc) · 1.29 KB
/
process
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
#!/bin/bash
RED_COLOR='\E[1;31m'
GREEN_COLOR='\E[1;32m'
YELOW_COLOR='\E[1;33m'
RES='\E[0m'
case "$1" in
grep)
if [ $2 ]
then
ps aux | grep $2 | grep -v grep
else
echo -e "${RED_COLOR}process name needed ${RES}"
echo "format: grep 'process name parts'. eg. grep php"
fi
;;
kill)
if [ $2 ]
then
ps aux | grep $2 | grep -v grep | awk '{print $2}' | xargs kill -9
else
echo -e "${RED_COLOR}process name needed ${RES}"
echo "format: kill 'process name parts'. eg. kill php"
fi
;;
mem-all)
if [ $2 ]
then
ps aux | grep $2 | awk '{print $6/1024}' | awk '{sum += $1}; END {print sum " MB"}'
else
ps aux | awk '{print $6/1024}' | awk '{sum += $1}; END {print sum " MB"}'
fi
;;
mem-avg)
if [ $2 ]
then
ps aux | grep $2 | awk '{print $6/1024;}' | awk '{avg += ($1 - avg) / NR;} END {print avg " MB";}'
else
echo -e "${RED_COLOR}process name needed ${RES}"
echo "format: mem-avg 'process name parts'. eg. mem-avg php"
fi
;;
*)
echo -e "${GREEN_COLOR}Available options: grep |kill |mem-all |mem-avg ${RES}"
;;
esac