Bor*_*ort 6 command-line dconf
下面的场景假设我们启动了计算机并在登录菜单中以用户 bort 的身份登录。这是在 14.04.2。
如果我打开一个终端,作为用户 bort,我可以列出一个 dconf 设置,例如
$ dconf read /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode
0
Run Code Online (Sandbox Code Playgroud)
如果我使用 dconf write 将值更改为 1,屏幕左侧的菜单将被隐藏
$ dconf write /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode 1
$ dconf read /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode
1
Run Code Online (Sandbox Code Playgroud)
现在菜单被隐藏了。现在假设我使用 dconf write 将其设置回 0。菜单将再次出现。
现在,如果我以 root 用户身份在一个终端中并尝试使用 su bort -c 更改 bort 的值,我可以更改它。我知道这一点,因为在我是用户 bort 的另一个终端中,我可以使用 dconf read 并看到该值已更改为 1。因此该值已更改但屏幕左侧的菜单仍然可见。如何使更改实际应用而不是仅在 dconf 数据库中更新?最终,我想知道这与 Puppet 的 exec 类型一起使用,但是能够以 root 身份从终端执行此操作将有助于实现该目标。
在终端中以 root 身份:
# su bort -c "/bin/sh -c '/usr/bin/dconf write /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode 1'"
Run Code Online (Sandbox Code Playgroud)
运行上一个命令后在终端中作为 bort :
$ dconf read /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode
1
Run Code Online (Sandbox Code Playgroud)
然而菜单还在那里。我知道此类问题在此站点上有一些答案,例如使用 dbus-launch 但这对我不起作用。也许它是特定于 Ubuntu 版本的?
小智 4
您没有设置 DBUS_SESSION_BUS_ADDRESS 环境变量,因此更改不会保留。作为您的用户,写下以下输出
echo $DBUS_SESSION_BUS_ADDRESS
Run Code Online (Sandbox Code Playgroud)
然后在 root 命令中使用
export DBUS_SESSION_BUS_ADDRESS=xxxxx && dconf write ...
Run Code Online (Sandbox Code Playgroud)
哪个应该有效。
在与他们隐藏套接字的蹩脚尝试作斗争之后,自动获取地址的一个有效解决方案是通过进程环境借用它:
# requires a GUI session program that will always run:
p=`pgrep -u \`whoami\` gnome-panel`
r=`grep -z DBUS_SESSION_BUS_ADDRESS /proc/$p/environ | sed 's/^[^=]*=//'`
export DBUS_SESSION_BUS_ADDRESS=$r
Run Code Online (Sandbox Code Playgroud)
当然,如果您不运行 gnome-panel,则必须选择 gnome-panel 以外的其他选项。
也适用于 SSH_AUTH_SOCK。把这个留在这里,这样它可能会帮助那些迄今为止谷歌搜索不成功的人(比如我;))。
在 CentOS 8.3 上,以下内容适用于更新dconf设置。
$user是上述问题标题中的另一个用户。
dbus-run-sessiondbus是在命令行模式下启动会话的推荐方法。无需导出任何DBUS_SESSION变量,例如BUS_ADDRESSPID 或 PID。
# start a new dbus session and execute the dconf command in bash shell
sudo -i -u ${user} bash <<-EOF
exec dbus-run-session -- bash -c 'dconf write /org/gnome/software/download-updates false'
EOF
Run Code Online (Sandbox Code Playgroud)
要了解更多信息,请阅读联机帮助页:man dbus-run-session和man dbus-launch
我想,这应该可以在 Ubuntu 上运行(未经测试)