开发者

Executing a python script from inittab not as root

I have a python script which I would like to launch from inittab, shown below

s1:respawn:/home/a_user/app/script.py

I believe initab executes as root, so the a_user's envrinment is not available

The script needs to know "a_user" home directory for ini file settings and log file storage. I would like to avoid hard coding these paths in my script. Is it possible to execute this script as开发者_如何学编程 a_user and not a root? If this is possible would a_user HOME environment variable be available?

Regards


Use runuser (or the distro's equvalent) to run it as a different user. runuser does change $HOME, but other similar commands may not.


you could copy python binary to python-suid, chown it to user you want to run scripts as and chown u+s python-suid

then in script #!/usr/bin/python-suid

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜