Skip to content

Instantly share code, notes, and snippets.

@road3x
Created February 2, 2018 08:50
Show Gist options
  • Save road3x/58d47081aa9fdc7865683731ccff08ae to your computer and use it in GitHub Desktop.
Save road3x/58d47081aa9fdc7865683731ccff08ae to your computer and use it in GitHub Desktop.
Kill processes that are running for more than few minutes
#!/bin/bash
PROCESS_NAME="gitlab-shell key"
for i in `ps aux | grep "$PROCESS_NAME" | grep -v root | gawk '{print $2 "_" $10}' | sed 's/://'`
do
PROCCESSNUM=`echo $i | cut -f1 -d'_'`;
TIMENUM=`echo $i | cut -f2 -d'_'`;
if [ $TIMENUM -gt 120 ]; then
kill $PROCCESSNUM;
# echo "kill $PROCCESSNUM at "`date`;
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment