wordpress meta
title: 'Gnome Desktop Shortcut Exec'
date: '2021-01-01T10:44:28-06:00'
status: publish
permalink: /gnome-desktop-shortcut-exec
author: admin
excerpt: ''
type: post
id: 1706
category:
- Bash
- Gnome
tag: []
post_format: []
title: 'Gnome Desktop Shortcut Exec'
date: '2021-01-01T10:44:28-06:00'
status: publish
permalink: /gnome-desktop-shortcut-exec
author: admin
excerpt: ''
type: post
id: 1706
category:
- Bash
- Gnome
tag: []
post_format: []
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
```bash Exec=gnome-terminal --profile=job-output -e 'sudo /home/rrosso/scripts/rsync-TANKs-2TBUSB.sh' ````
Update IP address in a remote firewall
```bash 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:
``bash
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:
``bash
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"
````