Passing su password in shell script

烂漫一生 提交于 2019-12-06 05:04:10

The best way of doing this is with sudo, but since you don't want the best solution, you can you can use script instead:

{ sleep 3; echo "yourpassword"; } | script -q -c 'su -c whoami' /dev/null

This will print root, the output of whoami.

Please make sure to try this command verbatim (with password replaced) before trying to adapt it to run your own commands, since adapting it is difficult and error prone.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!