I’ve had the need to find out the actual username of someone logged in and working as root (via sudo su -) to put it into a subversion commit message. This quick little bash script does the trick, and just echos the username.

#!/bin/bash

PID=$$ # get PID of current process
LogUID=`cat /proc/"$PID"/loginuid` # get loginuid of current process
username=`getent passwd "$LogUID" | awk -F ":" '{print $1}'` # translate loginuid to username
echo "$username"


Comments

comments powered by Disqus