Skip to content

Instantly share code, notes, and snippets.

@garenyondem
Created March 4, 2019 12:55
Show Gist options
  • Save garenyondem/dbd1c25c3e247feac2295a74e528601e to your computer and use it in GitHub Desktop.
Save garenyondem/dbd1c25c3e247feac2295a74e528601e to your computer and use it in GitHub Desktop.
#!/bin/bash
# Get ids of processes running longer than 6 hrs (21600 secs)
PIDS=$(ps eaxo etimes,bsdtime,pid,comm,cmd | grep node | grep command-line-processes | awk '{if ($1 >= 21600) print $3}')
for i in ${PIDS};
do {
PROC_FILE_PATH=$(ps eaxo pid,cmd | grep node | grep "$i"| awk '{print $3}');
SCRIPT_NAME=$(basename "$PROC_FILE_PATH");
printf "Killing $SCRIPT_NAME\n";
kill $i;
};
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment