I have a Bash script on server A that finds the logged in SSH user via the logname command, even if it’s run as root with sudo. If I SSH into server A from my desktop and run the script, it works fine.
However, I’ve set up a post-commit hook on SVN server S which SSH’s into A and runs the script there, which causes logname to fail, with error “logname: no login name”.
If I SSH into S from my desktop, then SSH into A from there, it works correctly, so the error must be in the fact that the SVN hook ultimately does not run from a virtual terminal.
What alternative to logname can I use here?
You could use the
idcommand:However
In a bash script you can cut the username out of the id output with something like
To have a script that works both in a sudo environment and without a terminal you could always execute different commands conditionally.