From 713fffee966b04dc91c1174471d5c0b4142479bf Mon Sep 17 00:00:00 2001 From: Matheus Albino Brunhara Date: Tue, 2 Apr 2024 14:02:16 -0300 Subject: [PATCH] Add scripts/shell/job/gp/gp-kill.sh file --- scripts/shell/job/gp/gp-kill.sh | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 scripts/shell/job/gp/gp-kill.sh diff --git a/scripts/shell/job/gp/gp-kill.sh b/scripts/shell/job/gp/gp-kill.sh new file mode 100755 index 0000000..938c45a --- /dev/null +++ b/scripts/shell/job/gp/gp-kill.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +show_help() { + echo "Usage: $0 [--grep-str|-g string]" + echo "Options:" + echo " --help | -h (Optional) Display help information on how to use this script" + echo " --grep-str | -g (Optional) Specify a customized string for grepping the process description" +} + +grep_str='8788' + +while [ "$#" -gt 0 ]; do + case "$1" in + --help|-h) show_help; exit ;; + --grep-str|-g) grep_str="$2"; shift 2;; + *) shift ;; + esac +done + +function confirm() { + while true; do + read -p '' yn + case $yn in + [Yy]* ) return 0;; + [Nn]* ) return 1;; + [Cc]* ) exit;; + * ) echo "Please answer YES, NO, or CANCEL.";; + esac + done +} + +process_out=`ps -A -U $(whoami) --format pid=,cmd= | grep $grep_str | sed -n '2p'` +IFS=' ' read -r p_id p_cmd <<< "$process_out" + +echo "CMD: \"$p_cmd\"" +echo "Kill it? (Yy/Nn/Cc)" + +if confirm; then + kill -9 $p_id + echo "[INFO] Process was killed." +else + echo "[INFO] Process was not killed." +fi