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
    kill -TERM $PROC

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

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

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
    kill $signal 
         $(find /proc -name [1-9]* -maxdepth 1 -user tony -mtime +0 | cut -d/ -f3)
    sleep 3


Tags: , , , , , ,