Skip to content

Instantly share code, notes, and snippets.

@coderofsalvation
Last active February 14, 2025 09:23
Show Gist options
  • Save coderofsalvation/5dca9fcc74c0044d1232cba164a0f06d to your computer and use it in GitHub Desktop.
Save coderofsalvation/5dca9fcc74c0044d1232cba164a0f06d to your computer and use it in GitHub Desktop.
shellscript which forwards filesystem inotify events to webpage [inotify-tools + websocat]
#!/bin/sh
echo '
<h1>/tmp watcher</h1>
<pre>
try: $ touch /tmp/FOO
$ chmod +x /tmp/FOO
$ xattr -s foo -V bar /tmp/FOO
</pre>
<pre id="log">
output
======
</pre>
<script>
var ws = new WebSocket("ws://127.0.0.1:'$PORT'/");
ws.onmessage = function(event) {
document.querySelector("#log").innerHTML += "\n"+event.data;
};
</script>
' > /tmp/index.html
echo "point your browser to: https://127.0.0.1:9090"
inotifywait -m /tmp | websocat -E -s 9090 -F /:text/html:/tmp/index.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment