Last active
April 9, 2021 22:08
-
-
Save benok/3c9715c8d6a66a0171f6a3d3c287cd25 to your computer and use it in GitHub Desktop.
Enable "ps [-p] PID" for /bin/ps from busybox (like Alpine Linux)
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
#!/bin/sh | |
# enable "ps [-p] PID" for /bin/ps from busybox (like Alpine) | |
# copy this script as /usr/local/bin/ps or /usr/bin/ps, and chmod 755 it. | |
if [ $# == 1 ]; then | |
echo $1 | grep -q -E '^[0-9]+$' # number only argument | |
if [ $? == 0 ]; then | |
OPT_P=1 | |
ARG_P=$1 | |
fi | |
else | |
for OPT in "$@" | |
do | |
case "$OPT" in | |
'-p') | |
OPT_P=1 | |
ARG_P=$2 | |
shift 2 | |
;; | |
esac | |
done | |
fi | |
if [ x$OPT_P == x1 ]; then | |
/bin/ps -o pid | grep -q $ARG_P # grep pid only | |
RET=$? | |
/bin/ps | egrep "^(PID| *$ARG_P )" # show output like normal ps | |
exit $RET | |
else | |
/bin/ps $* | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment