Last active
July 24, 2020 14:30
-
-
Save RecNes/8fcc6c83b6e36317dc6c72dd09dd31ec to your computer and use it in GitHub Desktop.
Shell script to use for kill all python scripts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# title : kill_pyhton.sh | |
# description : This script to use for kill python scripts. | |
# author : Sencer HAMARAT "sencerhamarat(at)gmail.com" | |
# date : 20160202 | |
# version : 0.1 | |
# command : bash kill_pyhton.sh | |
# bash_version : 4.3.11(1)-release | |
# ============================================================================= | |
ARGS="$@" | |
SCRIPTS=(`ps x | grep python | grep -v ".pyc" | grep -v grep | awk '{print $NF}'`) | |
kill_funct () { | |
if [ !-z "$1" ]; then | |
kill -9 "$1" | |
echo "$1 is killed." | |
fi | |
} | |
killall_funct () { | |
echo "WARNING: Killing any of script is may harm your system. BE CAREFUL!" | |
echo "" | |
for SCRIPT in ${SCRIPTS} | |
do | |
read -r -p "Do you really want to KILL $SCRIPT ? [y/N] " response | |
resp=${response,,} | |
if [[ ${resp} =~ ^(yes|y)$ ]]; then | |
# kill -9 ${SCRIPT} | |
echo "$SCRIPT is killed." | |
else | |
echo "$SCRIPT is leaved as alive." | |
fi | |
done | |
} | |
if [ -z ${ARGS} ]; then | |
echo "No file name or key given as parameter." | |
echo "For help please use -h key." | |
else | |
for ARG in ${ARGS} | |
do | |
if [ ${ARG} = "-h" ]; then | |
echo "Python script killer." | |
echo "WARNING: Killing any of script may harm your system. BE CAREFUL and use it your own risk!" | |
echo "" | |
echo "USAGE:" | |
echo " -h : Displays this help" | |
echo " \"file name\" : Kills the process of the given file names" | |
echo " You can give more than one file name as argument" | |
echo " E.G. bash oldur.sh \"file1 name\" \"file2 name\" ..." | |
echo " All : This parameter kills all python processes found with 'ps' command" | |
echo " (THIS ARGUMENT MAY CAUSE THE DEATH OF THE UNDESIRED SCRIPTS. Use carefully!)" | |
elif [ ${ARG} = "All" ]; then | |
killall_funct | |
else | |
if [[ ${SCRIPTS[*]} =~ ${ARG} ]]; then | |
kill_funct ${ARG} | |
else | |
echo "${ARG} not present as a process." | |
fi | |
fi | |
done | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment