{"id":1706,"date":"2021-01-01T10:44:28","date_gmt":"2021-01-01T16:44:28","guid":{"rendered":"https:\/\/blog.iqonda.net\/?p=1706"},"modified":"2021-01-01T11:04:12","modified_gmt":"2021-01-01T17:04:12","slug":"gnome-desktop-shortcut-exec","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/gnome-desktop-shortcut-exec\/","title":{"rendered":"Gnome Desktop Shortcut Exec"},"content":{"rendered":"

Executing commands or scripts from a GNOME desktop shortcut<\/h1>\n

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.<\/p>\n

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<\/a><\/p>\n

For my purposes here are example entries from .desktop files:<\/p>\n

Rsync to USB<\/p>\n

Exec=gnome-terminal --profile=job-output -e 'sudo \/home\/rrosso\/scripts\/rsync-TANKs-2TBUSB.sh'<\/code><\/pre>\n

Update IP address in a remote firewall<\/p>\n

Exec=gnome-terminal --profile=job-output -- \/bin\/sh -c 'cd \/TANK\/DATA\/MySrc ; python3 ip-add-iqonda-aws.py ; sleep 60'<\/code><\/pre>\n

Executing using bash with date in log file:<\/p>\n

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<\/code>-desktop-zfs-replicate-192.168.1.79.log\"<\/code><\/pre>\n

I also prefer using gnome-terminal so I can format the output on the screen better:<\/p>\n

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<\/code>-desktop-zfs-replicate-192.168.1.79.log ; sleep 60\"<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

Executing commands or scripts from a GNOME desktop shortcut I have a few scripts that I only periodically execute. For<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,33],"tags":[],"class_list":["post-1706","post","type-post","status-publish","format-standard","hentry","category-bash","category-gnome"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=1706"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1706\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=1706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=1706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=1706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}