You gotta love the UNIX way of doing things


A colleague was asking for some help in a demo he was planning on that would involve him editing a spreadsheet in LibreOffice on his laptop and then the spreadsheet to be saved to a remote machine. Once the edit to the spreadsheet was done, that act should then trigger a process in the remote machine. He could do that by manually firing off a process, but would like it to be automated.

Because of his question, I found out that in LibreOffice, there is an option to “Save Remote” which gives me a range of options to work with:

remote-add-service

 

remote-add-service-dialog

I could then just save to a SSH-enabled destination. Pretty cool.

Turned out, for some reason, the LibreOffice version on his machine just did not successfully connect to the ssh destination. It worked out of the box on my Fedora 28 and RHEL 7.5 systems. Hopefully, a bug report will be filed.

So, as an alternative, I suggested that perhaps he should do an sshfs (dnf install fuse-sshfs -y) link to the remote system. This allows for the remote location to be accessible from all apps on the local machine.

The next thing to do was to write a script on the remote end that watches the spreadsheet for changes and to trigger some actions.

This is where the UNIX philosophy of simple, well defined and well written tools come into play. It is also a realization that there are a million ways to make it happen.

In this instance, I picked on entr (dnf install entr -y on Fedora and via EPEL or RPMFusion for RHEL) which does exactly what was needed and all in just one line. I did initially consider inotify but figured entr was simpler for the task at hand.

Here’s a screencast to show two terminals (in Gnome, ctrl-alt-shift-R):

r7: is a RHEL 7.5 system (on the left) and gillman: is a Fedora 28 system (on the right).

The line “ls file.csv | entr -p ./p.sh” is all that is bring done on r7. On gillman, I sshfs mounted r7:/home/harish onto gillman:/home/harish/mnt. When the file file.csv is edited on gillman, the file is saved via the sshfs mount point onto r7 and on r7, the one line command line executes via entr to trigger the shell script “p.sh” which is nothing more than:

r7$ cat p.sh

#!/bin/sh
ping -c 5 127.0.0.1

The screencast is self explanatory.

Enjoy.

Advertisements

2 Comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.