I’ve found several solutions for finding out a user’s home directory of the user running said script, however, I’m writing a small script to make my life easier when creating vhost configurations for lighttpd or apache and would like to follow a scheme like so:
- /home/USER/html/example.com
- /home/USER/html/domain1.com
etc etc. However, I may decide at a later date whether I want to use /var/www/vhosts/example.com/public_html as a schema for certain domains.
The script, obviously has to run as root so it doesn’t make sense to execute os.getenv("HOME"). I realize I can simply concatenate homedir = "/home/%s/" % username though.
I was just curious whether anyone ran across any solution to retrieve a user’s home directory of someone who’s not executing the script.
You’re looking for
os.path.expanduser: https://docs.python.org/library/os.path.html#os.path.expanduser