Gnome Desktop Shortcut Exec
Executing commands or scripts from a GNOME desktop shortcut
I have a few scripts that I only periodically execute. For example a backup to a USB not always plugged in or to a computer not always online. For convenience I made some shortcuts on my GNOME desktop. I can easily just run these in a terminal of course but sometimes I just want to quickly click an icon and finish.
There are a few idiosyncracies around executing like this. In general you may have run into passing processes variables and redirection of output issues. In addition to those also "Exec" inside a desktop shortcut adds a few more issues. Read here for the Desktop Entry Specification
For my purposes here are example entries from .desktop files:
Rsync to USB
Exec=gnome-terminal --profile=job-output -e 'sudo /home/rrosso/scripts/rsync-TANKs-2TBUSB.sh'
Update IP address in a remote firewall
Exec=gnome-terminal --profile=job-output -- /bin/sh -c 'cd /TANK/DATA/MySrc ; python3 ip-add-iqonda-aws.py ; sleep 60'
Executing using bash with date in log file:
Exec=bash -c "sudo /root/scripts/zfs-replication.sh -w 1 -t 192.168.1.79 | tee /TANK/backups/logs//bin/date +%%Y-%%m-%%d
-desktop-zfs-replicate-192.168.1.79.log"
I also prefer using gnome-terminal so I can format the output on the screen better:
Exec=gnome-terminal --profile=job-output -- bash -c "sudo /root/scripts/zfs-replication.sh -w 1 -t 192.168.1.79 | tee /TANK/backups/logs//bin/date +%%Y-%%m-%%d
-desktop-zfs-replicate-192.168.1.79.log ; sleep 60"