chiark / gitweb /
New notification mechanism 'userv'.
authorSimon Tatham <anakin@pobox.com>
Fri, 18 Dec 2015 17:23:59 +0000 (17:23 +0000)
committerSimon Tatham <anakin@pobox.com>
Fri, 18 Dec 2015 17:23:59 +0000 (17:23 +0000)
This makes an ssh connection to a specified host, and then invokes a
specified userv service provided by a specified user. The recipient
configuration is of the form 'userv SSH_HOST_ARG USERV_USER SERVICE',
e.g. I've been testing it myself with the line
    userv sgtatham@chiark sgtatham post-pizza
which causes the first argument 'sgtatham@chiark' to be passed to ssh,
and then the service command 'userv sgtatham post-pizza' to be invoked
on the target host.

The notification message is passed to the userv service via standard
input, because that seemed slightly easier than doing it as a
command-line argument (the latter would be easy enough to get through
userv uncorrupted, but less easy to get through the ssh command line
mechanism).

The userv service is invoked with a 2-second timeout, so if it needs
to do anything potentially long (like trying to make a network
connection over a maybe-not-up-yet secnet tunnel) then it should close
file descriptors and fork.

via-userv [new file with mode: 0755]

diff --git a/via-userv b/via-userv
new file mode 100755 (executable)
index 0000000..dbfd8b9
--- /dev/null
+++ b/via-userv
@@ -0,0 +1,15 @@
+#!/usr/bin/perl -w
+#
+# recipient format:
+#    userv HOST USER SERVICE
+
+use strict;
+die unless @ARGV==4;
+our ($msg,$host,$user,$service) = @ARGV;
+
+if (open PIPE, "|-", "ssh", $host, "userv", "-t", "2", $user, $service) {
+    print PIPE "$msg\n";
+    close PIPE;
+}
+
+die $! if $? != 0;