kdialog 进度条“对象不可访问”作为根用户
我有一个脚本,其中包含许多需要根权限的命令。我更喜欢使用 sudo 运行整个脚本,而不是在脚本中使用 sudo 运行所有这些命令。这样放在 sudoers 文件中也比较舒服。
sudo ./script.sh
但是,我想用 kdialog 进度条显示进度,但这不起作用。显示包含该栏的消息框,但在尝试更新进度时出现错误消息“对象不可访问”。
dcopRef=`kdialog --progressbar "Initialising..." 5` # works
dcop $dcopRef setProgress 1 # error object not accessible
我很确定这与用户权限有关,因为进度条代码可以工作,然后无需 sudo 即可调用脚本,但我不知道从哪里开始。有谁知道如何解决这个问题并仍然使用 sudo 调用脚本?
我正在使用 openSUSE 10.3 和 KDE 3.5.7
谢谢, 克里斯
I have a script containing lots of commands that need root rights. Instead of running all these command with sudo inside the script I prefer to run the whole script with sudo. This is also more comfortable to put it in the sudoers file.
sudo ./script.sh
However, I'd like to show the progress with a kdialog progress bar, which does not work. The message box containing the bar shows up but when trying to update the progress there is an error message "object not accessible".
dcopRef=`kdialog --progressbar "Initialising..." 5` # works
dcop $dcopRef setProgress 1 # error object not accessible
I'm pretty sure it has to do with user rights, since the progress bar code works then calling the script without sudo, but I have no idea where to start. Does anyone know how to fix this and still calling the script with sudo?
I'm using openSUSE 10.3 with KDE 3.5.7
Thanks,
Chris
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
终于我找到了解决我问题的方法!它并不漂亮,但它有效...
在“script.sh”文件中,您可以在 sudo 的帮助下以原始(非 root)用户身份访问进度条:
您必须明确允许 root 使用调用“kdialog”并且'dcop' 作为用户(虽然这看起来有点奇怪),首先将其添加到您的 sudoers 文件中:
Voilà。
Finally I found a way to solve my problem! It is not beautiful, but it works...
Inside the 'script.sh' file you access the progress bar as the original (not root) user with the help of sudo:
You must explicitly allow root to use call 'kdialog' and 'dcop' as user (although this seems a bit weird) by adding this to your sudoers file first:
Voilà.