Skip to content

Commit

Permalink
use the UID mode to sudo if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
brendangregg committed Jun 16, 2017
1 parent 1518401 commit 702072d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions jmaps
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ for pid in $(pgrep -x java); do

user=$(ps ho user -p $pid)
if [[ "$user" != root ]]; then
# make $user the username if it is a UID:
if [[ "$user" == [0-9]* ]]; then user=$(awk -F: '$3 == '$user' { print $1 }' /etc/passwd); fi
cmd="sudo -u $user sh -c '$cmd'"
if [[ "$user" == [0-9]* ]]; then
# UID only, run sudo with #UID:
cmd="sudo -u '#'$user sh -c '$cmd'"
else
cmd="sudo -u $user sh -c '$cmd'"
fi
fi

echo "Mapping PID $pid (user $user):"
Expand Down

0 comments on commit 702072d

Please sign in to comment.