-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathkillem.sh
executable file
·74 lines (64 loc) · 1.4 KB
/
killem.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/sh
DRYRUN=0
if [ "$1" = "--dry-run" ]
then
DRYRUN=1
shift;
fi
usage()
{
cat << EOF 2>&1
usage: ./killem.sh [--dry-run] [ client | server ]
If no arguments are given any snis_client, snis_server, snis_multiverse and ssgl_server
processes will be killed.
If "client" is specified, only snis_client processes will be killed.
If "server" is specified, only snis_server, snis_multiverse, and ssgl_server processes
will be killed.
If --dry-run is specified, no processes will be killed. --dry-run must be the
first argument to have any effect.
EOF
}
kill_pattern()
{
pattern="$1"
p=$(ps aux | egrep "$pattern" | grep -v 'grep')
if [ "$p" = "" ]
then
echo "There are no processes to kill."
return
else
echo "$p"
fi
if [ "$DRYRUN" != "1" ]
then
ps aux | egrep "$pattern" | grep -v 'grep' | awk '{ printf("kill %s\n", $2); }' | /bin/sh
echo "Killed the above processes."
else
echo "Dry run mode (would have killed the above processes.)"
fi
}
remove_lock_dirs()
{
for x in /tmp/snis_lock_dir.*
do
if [ -d "$x" ]
then
rmdir "$x"
fi
done
}
# Default is to Killem all
if [ "$1" = "" ]
then
kill_pattern 'ssgl_server|snis_client|snis_server|snis_multiverse|snis_limited_client'
remove_lock_dirs
elif [ "$1" = "client" ]
then
kill_pattern 'snis_client|snis_limited_client'
elif [ "$1" = "server" ]
then
kill_pattern 'snis_server|snis_multiverse|ssgl_server'
remove_lock_dirs
else
usage
fi