1

I'm working on a script to set some particular gsettings. If the script is being executed as user its working as expected. But, because of some reason I need my script to work with sudo.

One solution i found was to use sudo -u <username> -H ./script to run it in user space. It is getting executed without any error, but my changes are not taking place in the user space.

I unable to understand what am I missing here. When i run sudo -u <currentUser> -H bach -c `echo " $USER $UID"` it is working as expected and giving the user values.

What might be the issue here?

Thanks in advance!

  • Please 1. tell us what you try to do; and 2. what happens instead. Can you see the changes taking place somewhere else or nowhere? – sudodus Nov 29 '19 at 09:00
  • @sudodus What i try to do: Change the desktop wallpaper ............

    What happens: The script is executed with out any error, and says wall paper has been changed. ................

    No, I can't see my changes anywhere else.. I'm guessing the changes are being made for 'root'.

    – frankenstein Nov 29 '19 at 11:22
  • 1
    @frankenstein I have tried with a script only for changing wallpaper to user, it is working as expected. do you have any other thing in script other than gsettings? – PRATAP Nov 29 '19 at 13:16

1 Answers1

1

the reason is you are not using dbus-launch infront of gsettings command.

see man dbus-launch

if you run sudo -Hu user gsettings set org.gnome.desktop.background picture-uri '' you will get error

administrator@pratap:~/Music$ sudo -Hu user gsettings set org.gnome.desktop.background picture-uri ''

(process:11889): dconf-WARNING **: 18:54:53.409: failed to commit changes to dconf: Error spawning command line “dbus-launch --autolaunch=454398a8b6e94accb53d9b7e5361faaa --binary-syntax --close-stderr”: Child process exited with code 1
administrator@pratap:~/Music$

enter image description here

enter image description here

enter image description here

enter image description here

PRATAP
  • 22,460
  • Hi, I've tried the exact same setup in my system.. and it got executed without giving any error.. But, nothing has changed. I'm very much clueless why it isn't working. – frankenstein Dec 02 '19 at 09:48
  • If it may provide a better picture of the problem, please take a look at https://askubuntu.com/questions/1193164/trouble-with-handling-sudo .. thank u! – frankenstein Dec 02 '19 at 09:50
  • Hi, can you once check sudo -u <current_user> -H gsettings set org.gnome.desktop.background picture-uri file:///path/to/file
    I'm finding this weird behavior, in the same session if we try to 'gsettings get' the desktop picture, it shows the picture set by us.. but its not applied to the system..
    – frankenstein Dec 03 '19 at 09:56
  • and once we log off and login (or weirdly, if we open and close the background settings UI), we see that the value set by us is lost and not the 'gsettings get' will give the correct picture reference. – frankenstein Dec 03 '19 at 09:57
  • yes, I've tried it.. but i got similar response.. nothing being set.. If it isnt toomuch trouble.. pls take a look at https://askubuntu.com/questions/1193415/sudo-u-current-user-h-gsettings-set-org-gnome-desktop-background-picture-uri?noredirect=1#comment1998002_1193415 – frankenstein Dec 03 '19 at 11:20
  • I've partially got close to why it aint woking – frankenstein Dec 03 '19 at 11:21
  • The changes made are persistent? – frankenstein Dec 03 '19 at 11:25
  • right now I have the picture in user/Downloads.. but, I've also tried from /usr/share/backgrounds/.. it did not work.. – frankenstein Dec 03 '19 at 11:34
  • One thing ive learnt is..this is happening coz of missing an env variable DBUS_SESSION_DBUS_ADDRESS. When we are using sudo -Hu <user> env > text.txt we get a very limited subset of env varables.. in which the above variable is missing.. – frankenstein Dec 03 '19 at 11:36
  • I am using Ubuntu 18.04 out of box.. with out doing any changes to env. see the pics in edited Answer. – PRATAP Dec 03 '19 at 11:43
  • Thank you very much for your efforts.. As i mentioned in above comment, I've kinda made it working by setting the env variable mentioned above...
    I still dont understand why it is working fine for you.. anyways thanks again!
    – frankenstein Dec 03 '19 at 11:51