Identify user in a Bash script called by sudo

前端 未结 7 2119
闹比i
闹比i 2020-12-07 14:39

If I create the script /root/bin/whoami.sh containing:

#!/bin/bash
whoami

and this script is called by a user with a properly

7条回答
  •  余生分开走
    2020-12-07 14:50

    Using whoami, who am i, who, id or $SUDO_USER isn't right here.

    Actually, who is never a solution to the question, as it will only list the logged in users, which might be dozens...

    In my eyes, the only valuable answer is the use of logname.

    Hope this helps

    Rob

提交回复
热议问题