Xterm launched instead of Tilix

Hi,

I made a launcher that contains :

[Desktop Entry]
Name=Sauvegarder DATA
Comment[fr]=sauvergarder /media/DATA/ vers /media/django/SAUV_2020/DATA/
Icon=backup
GenericName=backup DATA
Exec=sudo rsync -va --delete-after /media/DATA/ /media/django/SAUV_2020/DATA/
Terminal=true
StartupNotify=false
Type=Application
Categories=Utility;
Keywords=backup;sauvegarde;

…it works as I expect unless for the Terminal : Xterm gets launched, I was expecting Tilix.

Is there a way to do it « through » Tilix ?

I had the same issue. Inside of “/usr/bin”, I simply created a symlink to tilix named “xterm”.

Ooh yes… why didn’t I think about it, lol ?

Any potential downside ?

Or should that be a default « setting » @fossfreedom ?


Mmm… there’s already an item for xterm in my /usr/bin

django@ASGARD:~$ ls -l /usr/bin/
total 648032
(…)
-rwxr-xr-x 1 root root     3290656 févr. 20  2020 tilix
(…)
-rwxr-xr-x 1 root root      796320 févr. 22  2021 xterm

There may be another way with :

Exec=tilix -e "sudo rsync -va --delete-after /media/DATA/ /media/django/SAUV_2020/DATA/"

or

Exec=x-terminal-emulator -e "sudo rsync -va --delete-after /media/DATA/ /media/django/SAUV_2020/DATA/"

Unfortunately GTK libraries do not have the ability to set the default terminal. The terminals it supports are limited - gnome-terminal & xterm and a few others. Tilix is not one of them.

You can use a similar workaround as @Underdog mentioned

sudo ln -s /usr/bin/tilix /usr/bin/nxterm

This ensures xterm is not the default terminal - nxterm doesnt exist in the repos so it should be pretty safe to hijack for this purpose.

I don’t understand how having a symlink named nxterm may launch the symlinked tilix when xterm is called ? What’s the rationale behind ?

In the other hand,

x-terminal-emulator -e "sudo rsync -va --delete-after /media/DATA/ /media/django/SAUV_2020/DATA/"

launches Tilix with the expected command so it seems Tilix is associated one way or another as the « default » system terminal on UBudgie.

What I can’t manage so far with « x-terminal-emulator » is keeping Tilix’s window opened once the command is done. It just closes, preventing the ability to check what happened.

If I set « hold terminal opened » after a command is done in Tilix preferences, I get an header message « child process stopped normally with signal ×× » offering to relaunch but that fails again hence that terminal remains unusable.

So maybe the strategy is writing a more elaborate script which would contain :
⋅ the backup rsync command,
⋅ instruction to print the output from that command in a file instead of terminal itself,
⋅ to name that file as « sauv_DATA_date_time » and save it at root of the backup destination
⋅ to open that file once the backup is done

…but I don’t know how to do that.

Odd. I can’t see my doing this if there had already been a file there for xterm and I actually documented my customization immediately afterwards in case I later needed to do a re-install of UB. I wonder why my folder didn’t have a file there for xterm already. Or did I maybe document the wrong folder? Anyway, I’m running 20.04 if it matters.

Perhaps nxterm gets considered ahead of xterm? I don’t know. Just a guess…

20.04 here too.

Or maybe xterm is not supposed to be in my /usr/bin ?

Or… is there a trick with /etc/alternatives/x-terminal-emulator ?

There x-terminal-emulator symlinks to /usr/bin/tilix.wrapper

I’d say that I documented the wrong folder except that there does in fact exist a symlink in /usr/bin just like my documentation states. It’s weird that the file was there in your case but not mine.

Assuming that what foss recommended didn’t work for you, perhaps you could rename the xterm file that already exists and then add the symlink to “tilix” named “xterm”?

I think I know why xterm is installed by my side : it came with multisystem.

xterm may not be installed by default on UBudgie. Is it @fossfreedom ?

This would explain why you - logically - did not find xterm in your /usr/bin.


So I’ve tried the symlink trick :

django@ASGARD:~$ ls -l /usr/bin | grep term
(…)
lrwxrwxrwx 1 root root          37 oct.   1 01:25 xterm -> /etc/alternatives/x-terminal-emulator
lrwxrwxrwx 1 root root          37 mars  22  2020 x-terminal-emulator -> /etc/alternatives/x-terminal-emulator
django@ASGARD:~$ 

and my launcher is as is :

[Desktop Entry]
Name=Sauvegarder DATA
Comment[fr]=sauvergarder /media/DATA/ vers /media/django/SAUV_2020/DATA/
Icon=backup
GenericName=backup DATA
Exec=sudo rsync -va --delete-after /media/DATA/ /media/django/SAUV_2020/DATA/
Terminal=true
StartupNotify=false
Type=Application
Categories=Utility;
Keywords=backup;sauvegarde;

but…


…the error about the command itself is normal since I did not plug in my external HDD.

What worry me are
⋅ the blue header that hides the terminal output
⋅ the fact this terminal does not give me back « hand », I can’t do anything in it in that state,
except [ relaunch / relancer ] or close Tilix’s window.

Here is the same grep output for me:

bwblock@Typhon:/usr/bin$ ls -l | grep term
-rwxr-xr-x 1 root    root        2745 Apr  8  2020 dh_strip_nondeterminism
-rwxr-xr-x 1 root    root       47336 Jul 21  2020 setterm
lrwxrwxrwx 1 root    root          14 Jul  3  2020 xterm -> /usr/bin/tilix
lrwxrwxrwx 1 root    root          37 Jun 29  2020 x-terminal-emulator -> /etc/alternatives/x-terminal-emulator

What happens if you rename xterm to xterm_old and then add an “xterm” symlink to tilix? It seems like that should work. Granted, it’s a hack and long-term it could cause problems. In my case it’s worked just fine but again, I just added a symlink – I didn’t have to rename xterm.

I uninstalled xterm and multisystem.

Symlink works.

But the behavior of Tilix once command is done bugs me a little…

You will probably need to pause after the command is run

So wrap the sync into a bash script using something like this

I’m afraid it will behave the same after the pause. I did not try yet as I’m not comfortable with script.

At the end I just want a « launcher » stored on the HDD, which :
⋅ well, launches the backup,
⋅ tells me it’s ok and done or not ok there has been a problem.

I don’t mandatory need a view on a terminal while it’s doing the backup.
I just thought it was the easiest way from within a .desktop file ( Terminal= true ) - but by default the terminal closes once command done ( I changed that in Tilix preferences ).

Hence the second idea, keep
Terminal= false
and use
Exec= x-terminal-emulator -e "command"
instead.

But both end in the same way : terminal holds open with a header message ( that hides a part of the command output ) and unusable ( it’s only possible to relaunch same command or close the window ).

I suspect the answer is there How can I make a script that opens terminal windows and executes commands in them? - Ask Ubuntu but I don’t understand how / where I’m supposed to use it. + it’s quite an old answer.

Yep. I do basically what foss recommends in my own scripts when I need the terminal to remain open. As you’re implementing a backup script using rsync, I’d be happy to share mine if you like. It’s a general purpose bash script that enables you to simply drag/drop a folder onto its launcher on the dock and it then rsync copies any changes made beneath that folder to a pre-determined backup server on your network (just supply the IP and username). For it to work, I believe you have to have the same username on both computers. So after doing a bunch of work on my desktop, at the end of the day I just drag and drop my top-most (~/Root) folder (or a more specific folder if know that my changes are limited to it) onto the launcher and in seconds, all my work for that day is completely backed up. The only thing is, the script makes use of piping via an app that I wrote some years back and so the script is mostly only useful to see how this kind of backup is basically implemented in bash script. Not to say that you aren’t welcome to use the piping tool but it’s developed in C# and I haven’t met a Linux user yet who feels that the Mono runtime is worth installing. I can’t say that I blame 'em. I’m thinking of re-writing the app in Vala and then it will essentially have only Gtk as its dependency (on a Gnome-based system that is).

Your insight is much appreciated @Underdog thanks !
Unfortunately I am a rather basic user with ( almost ) zero knowledge in vala or C#.

And to be honest, my 2 .desktop files basically do what I expect.

I’m just surprised terminal does not get back to an « usable » and « readable » state after the command but readable enough to check if the backup has been done or not.

No need for you to know either C# or Vala. It’s just a bash script (see code below). As it currently exists, the script would only be useful to see how to implement backing up a folder to a remote server. Minus the blank lines, comments and help functionality, it’s just about 25 lines long and thus pretty simple to digest. If you wanted to use the script, there’s just a few lines of piping logic that would need to be replaced using something like sed or awk. Unfortunately, I’ve never used either of these tools and so I couldn’t provide any help with using them.

I’m surprised too. That’s so strange!


if [ $# -eq 1 ] ; then

   # All arguments are provided.

   SOURCE="$1"
      # The file or folder to copy to the backup server.
   BUSIP="remote IP address"
      # The backup server's IP address. BE SURE TO SET THIS TO YOUR SERVER'S IP!
   USERNAME="your username"
      # The user on both the client and server computers. BE SURE TO SET THIS TO YOUR USERNAME!
   DESTPREFIX="$USERNAME@$BUSIP:"
      # This is the prefix of the destination file name.
   PARENTDIR="'"$(echo $SOURCE | pcl "ReverseChars | ShiftChars 1 '/' | DelChars 1 1 | \
   ReverseChars | ReplStr '''' '''\"''\"'''")"'"
      # This is the parent folder under which <source> will be copied on the
      # backup server. It is constructed from the original <source> by first
      # removing its lowest level component and then by escaping those characters
      # that would otherwise be interpreted by the remote shell, such as spaces,
      # etc. This second step is achieved by replacing embedded single quotes
      # found inside of the resulting folder name with the sequence, ('"'"')
      # and then by enclosing that result in single quotes.
   EXITCODE=0
      # Assuming successful execution.

   if [[ -f "$SOURCE" || -d "$SOURCE" || -h "$SOURCE" ]] ; then

      # The provided source is an existing file, folder or symlink.

      CHECK=$(echo $SOURCE | pcl "InclLines '^/home/$USERNAME/' /r")
      if [ "$CHECK" != "" ] ; then

         # The source is from inside of the user's home folder.
         # Copy it to the backup server as requested:

         echo -e "syncfiles rel 2.0\n"
         echo -e "Executing: rsync -a \"$SOURCE\" \"$DESTPREFIX$PARENTDIR\"\n"
         if ! rsync -az --delete --progress "$SOURCE" "$DESTPREFIX$PARENTDIR" ; then

            # Oops!

            EXITCODE=4
            echo -e "syncfiles: Failed to copy source to backup server.\n"
         fi
      else

         # Oops!

         EXITCODE=3
         echo -en "syncfiles: The source either isn't specified as an absolute "
         echo -e "path or it is located outside of your home folder.\n"
      fi
   else

      # Oops!

      EXITCODE=2
      echo -e "syncfiles: The specified source is not an existing regular file, folder or symlink.\n"
   fi

else

   # No arguments were provided. Display help:

   echo -e "\nsyncfiles - copy workstation file or folder to a \"backup server\"\n"
   echo -e "This script copies the given file, folder or symlink (located in or below"
   echo -e "your home folder) to the corresponding location on a remote \"backup\""
   echo -e "server.\n"
   echo -e "Usage: syncfiles <Source>\n"
   echo -e "where:\n"
   echo -e "   <Source> is the absolute path name of a file or folder beneath your home"
   echo -e "   folder that you wish to copy to the backup server.\n"
   EXITCODE=1
fi

#if [ "$EXITCODE" != "0" ] ; then

   # Pause the script so that any text output can be noted:

   read -n1 -r -p "Press a key ..." 
   echo -e ""
#fi

exit $EXITCODE