-
Notifications
You must be signed in to change notification settings - Fork 1
/
kill.sh
executable file
·44 lines (39 loc) · 1.11 KB
/
kill.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
#!/bin/sh
#
# Prevent accidentally killing all processes.
# Ask confirmation message if any of the parameters is -1, 0 or 1.
# It is completly transparent otherwise.
#
# Goes together with adding an alias to file /etc/profile.d/alias.sh
# alias kill="/usr/local/bin/kill.sh"
#
# Author: Hugo Ferreira
#
DANGER=0
CMD=kill
if [[ "$#" == "0" ]]; then
echo "(using wrapper: $0)"
fi
for i in $*; do
case $i in
'-1') DANGER=1; MSG='-1 (all processes with pid larger than 1)'; break;;
'0') DANGER=1; MSG='0 (all processes in the current process group)'; break;;
'1') DANGER=1; MSG='1 (main process "init" - will cause shutdown)'; break;;
esac
done;
if [[ $DANGER == 1 ]]; then
echo
echo `whoami`": WARNING! Killing "$MSG
echo `whoami`": Are you sure?"
select result in yes no; do break; done;
if [[ $result == 'yes' ]]; then
echo "(killing...)"
echo
else
echo "(aborting...)"
echo
exit -1
fi
fi
# Execute the command
$CMD $*