0

I followed the instructions here to set up an automated backup, such that whenever I connect a certain external drive to the computer, the backup is automatically started.

This works, but in addition I wanted to show two zenity dialogs to the user:

  • before backup is run to ask if the user really wants to do the backup (or just use the drive)
  • when backup is done to ask if the user wants to safely remove the drive (or use the drive)

Now my problem is that the backup script from the borg site is run as root. To be able to show the dialogs to the user, I added --display=:0.0 to the zenity commands and added this to my ~/.bashrc:

xhost local:$USER > /dev/null

The problem with this approach is: it only works once a terminal (i.e. the Gnome app) was started. If I just log into Gnome and plug in the drive, no dialog appears and I can read in sudo journalctl that the script failed because of this error:

zenity[2731]: cannot open display: :0.0

But if I open a terminal first, it works. I also tried adding the xhost command under /etc/profile.d/ but that didn't work even if a terminal was started.

So my question is: Where do I need to put the xhost command to make this work even if the user doesn't open the terminal app? Or how can it be done?

1
  • The problem is that you are trying to rely on ~/.bashrc or /etc/profile.d/*, neither of which is used by the GUI--there are only processed when you log in to a text based login, such as a terminal window. Read your shell's documentation. You will also have the issue of "what if no one is logged in when I plug the device in?" What you probably want is a udev trigger that can run a script or program to first check if a user is logged in to the GUI, and if so, then send a notification (you will have to ask another question specific to your setup for how to do this...)
    – C. M.
    Commented Jun 23, 2021 at 1:37

1 Answer 1

0

I wasted too much time on this and ended up adding the Gnome Terminal to autostart, so the ~/.bashrc file is read:

cd ~/.config/autostart
ln -s /usr/share/applications/org.gnome.Terminal.desktop

Not an elegant solution, but at least creating backups on the external drive is now straightforward.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .