-
Notifications
You must be signed in to change notification settings - Fork 0
/
python_proc_kill.sh
52 lines (41 loc) · 1.24 KB
/
python_proc_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
45
46
47
48
49
50
51
52
#!/bin/bash
while true
do
NAME_KILL="python"
#Time in seconds which the process is allowed to run
KILL_TIME=300
#Set UID
U_ID=10000
KILL_LIST=()
EMAIL_LIST=()
SEND_LIST=()
while read PROC_UID PROC_USER PROC_PID PROC_ETIMES PROC_ETIME PROC_COMM; do
if [ $PROC_UID -gt $U_ID -a "$PROC_COMM" == "$NAME_KILL" -a $PROC_ETIMES -gt $KILL_TIME ]; then
KILL_LIST+=("$PROC_PID");
MSG="Killing '$PROC_COMM' which runs for $PROC_ETIME";
echo "$MSG";
SEND_LIST+=($PROC_USER);
fi
done < <(ps eaxo uid,user:20,pid,etimes,etime,comm | grep -i $NAME_KILL)
if [ ${#KILL_LIST[*]} -gt 0 ]; then
kill -9 ${KILL_LIST[@]}
fi
if [ ${#SEND_LIST[*]} -gt 0 ]; then
com=`tty`
exec <$com
for i in "${SEND_LIST[@]}"
do
echo "Please do not run your job on Login/Master Node more then 5 Minutes Otherwise job will kill Automatically" | write $i;
#echo "$i"
done
if [ $? -eq 0 ]; then
echo "Warning Message has been sent successfully.............ok"
#return 0
else
echo "Message Failed to send ..............No!!"
echo "Maybe It is not available for you To send Message To hem "
#return 1
fi
fi
sleep 1m
done