-
-
Save ashsmith/55098099d2a5b5dfed9935dd4488abd6 to your computer and use it in GitHub Desktop.
Enable "ps [-p|--pid] PID" for /bin/ps from busybox (like Alpine Linux)
This file contains hidden or 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|--pid) | |
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
In alpine linux you can run
apk --no-cache add procps
and this should solve your issue without workaround script