0

Welcome, I have a short script to kill processes which works longer than specified time for UIDs bigger than. How to exclude for example mc command from killing?

#!/bin/bash
#
#Put the minimum(!) UID to kill processes
UID_KILL=500

#Put the time in seconds which the process is allowed to run below
KILL_TIME=300

KILL_LIST=`{
    ps -eo uid,pid,lstart | tail -n+2 |
    while read PROC_UID PROC_PID PROC_LSTART; do
SECONDS=$[$(date +%s) - $(date -d"$PROC_LSTART" +%s)]
if [  $PROC_UID -ge $UID_KILL -a $SECONDS -gt $KILL_TIME ]; then
    echo -n "$PROC_PID "
fi
done
}`

#KILLING LOOP
while sleep 1
do
    if [[ -n $KILL_LIST ]]
    then
        kill $KILL_LIST
    fi
done
Janek
  • 51
  • 10

1 Answers1

0

change inner command like this :

ps -eo comm,uid,pid,lstart | tail -n+2 | grep -v '^your_command' | ...

this will exclude 'your_command' from the list.

see STANDARD FORMAT SPECIFIERS in man ps for more about ps -o.

Farvardin
  • 5,336
  • 5
  • 33
  • 54