When to delete an abandoned project?
When it was coded it represented some of my best work. Some of it is still good. Some of it I look upon with horror. This posting is not about me and my code but about the code's life. I can say without any doubt that the code will never be used again. Even in part. Anything that was useful has already been subsumed into other projects. So why keep it? Why should SourceForge pay to keep it available? I don't have a good answer yet, but I am leaning towards deleting it.
A less violent killmatching
After reading my previous posting Jonathan Stockdill suggested that the command really needed dry-run and/or confirmation flags. He is right.
A challenge in doing this in bash was in coordinating the input from the ps pipeline and the user's confirmation. I came up with an answer but am not sure it is the right one and so have asked on Stackoverflow.com for help. Until then, here is a less violent killmatching:
#!/bin/bash -e
PS_OPTS=${PS_OPTS:- -A -o pid,command}
INTERACIVE=false
DRY_RUN=false
while [ 0 -ne $(expr $1 : '\-') ]
do
case "$1" in
-i) INTERACIVE=true ;;
-n) DRY_RUN=true ;;
-h) echo "usage: killmatching [-in] [kill-options] pattern1 pattern2 ... patternN" ; exit ;;
*) KILL_OPTS="$KILL_OPTS $1" ;;
esac
shift 1
done
exec 4<&0
for PATTERN in "$@"
do
ps $PS_OPTS \
| grep -v -F grep \
| grep -v -F "$0" \
| grep -e "$PATTERN" \
| while read PID COMMAND
do
if $INTERACIVE
then
read -u 4 -p "kill $PID $COMMAND? (y/N) " choice
if [ "$choice" == "Y" -o "$choice" == "y" ]
then
kill $KILL_OPTS $PID
fi
elif $DRY_RUN
then
echo kill $KILL_OPTS $PID
else
kill $KILL_OPTS $PID
fi
done
done
# END
Killmatching: a violent killall.
I always seem to need a better killall especially when running script or Java processes where the command name is, for example, "java". Scratching the itch, here is killmatching
#!/bin/bash -e
# usage: killmatching [ kill-options] pattern1 pattern2 ... patternN
PS_OPTS=${PS_OPTS:- -A -o pid,command}
while [ 0 -ne $(expr $1 : '\-') ]
do
KILL_OPTS="$KILL_OPTS $1"
shift 1
done
for pattern in "$@"
do
for pid in $(ps $PS_OPTS \
| grep -v -F grep \
| grep -v -F "$0" \
| grep -e "$pattern" \
| awk '{ print $1 }')
do
kill $KILL_OPTS $pid
done
done
Be very careful using it with one wrong pattern and you can shutdown the computer.
Some ps commands do not support the -A and -o options. Edit these options for your ps.