如何调整这个简短的 shell 脚本以满足我的需要?

sio*_*dus 2 command-line sudo

我试图powertop在使用 Ubuntu 中的启动应用程序向导登录时强制运行。在“命令”条目下,我已将gnome-terminal -x /home/***/Documents/programming/scripts/powertop.sh. 它使用单行 bash shell 脚本:

echo "******" | sudo -S powertop
Run Code Online (Sandbox Code Playgroud)

这正确输入了我的超级用户密码,但在初始化后不允许我与 powertop 交互,因为它一直在运行 echo。

如何获得使用 shell 脚本运行 powertop 的权限,但仍然能够在 gnome-terminal 中使用它?

小智 5

假设您的 powertop 在 中/usr/sbin,则sudo /usr/sbin/powertop无需密码即可使用。为此,您需要运行visudo并附加以下行,替换yourusername为真实的行:

yourusername ALL=(root) NOPASSWD: /usr/sbin/powertop
Run Code Online (Sandbox Code Playgroud)