Add scripts/shell/job/gp/gp-kill.sh file
This commit is contained in:
43
scripts/shell/job/gp/gp-kill.sh
Executable file
43
scripts/shell/job/gp/gp-kill.sh
Executable file
@@ -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 <string> | -g <string> (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
|
||||
Reference in New Issue
Block a user