shell - Runuser 命令在 ubuntu 启动时不起作用
问题描述
我创建了一个启动脚本,它使用runuser
命令来获取usersitepackages
python3。这在 时可以正常工作sudo /etc/init.d/myservice start
,但在设备启动时不行。
USER_NAME=$(if [ $(whoami) = "root" ]; then echo $SUDO_USER; else echo $USER; fi)
if [ $(whoami) = "root" ]; then
PKG_ROOT=$(runuser -l $USER_NAME -c "python3 -c 'import site; print(site.getusersitepackages())'")
CELERY_BIN=$(runuser -l $USER_NAME -c "which celery")
USER_HOME="/home/$USER_NAME"
else
PKG_ROOT=$(python3 -c 'import site; print(site.getusersitepackages())')
CELERY_BIN=$(which celery)
USER_HOME=$(echo $HOME)
fi
我想要 $PKG_ROOT 之类的/home/<user_name>/.local/lib/python3.7/site-packages
,但我总是得到/root/.local/lib/python3.7/site-packages
. 也不能使用 $USER_NAME。
解决方案
推荐阅读
- mysql - 我可以在 MYSQL 中禁用一个查询 ONLY_FULL_GROUP_BY
- python - 将二维数组转换为一维数组以创建数据框
- java - 将模型传递给子组件
- elixir - 十六进制包中的辅助函数
- c++ - boost asio 和 co_await 中断协程
- html - How to show horizontal ellipsis at bottom of the text
- sql - SQL: Apply and union table function recursively
- java - Get value of AWT-Choice and convert to an Integer for AWT-Graphics method fillOval(x, y, int1, int2);
- javascript - how to share link from my app to signal, bottom, email web and app?
- javascript - How do I add new field in existing JSON