How to kill all the processes that have dates older than today?

Now that you’ve done that, try something like this

# Find all process that are owner by "tony"
#  - Print out the process id (pid), and the start time (lstart)
# Find all the rows that aren't for today
# Cut that down to just the first field (process id)
PROCS="$(ps -u tony -o pid,lstart | fgrep -v " $( date '+%a %b %d' )" | cut -d' ' -f1)"

# Run through each process and ask it to shutdown
for PROC in $PROCS
do
    kill -TERM $PROC
done

# Wait for 10 seconds to give the processes time to stop
sleep 10

# Kill off any processes that still exist
for PROC in $PROCS
do
    [ -r /proc/${PROC}/status ] && kill -KILL $PROC
done

In linux, you can see all of your processes that are at least 24 hours old with

find /proc -name [1-9]* -maxdepth 1 -user tony -mtime +0

and take them out with something like

for signal in -TERM -HUP -KILL
do
    kill $signal 
         $(find /proc -name [1-9]* -maxdepth 1 -user tony -mtime +0 | cut -d/ -f3)
    sleep 3
done

									

Tags: , , , , , ,