Table of Contents

onfilechange

Watche a given fileobject or multiple fileobjects (=files or directories) and execute a command if it changes.

It loops permanently; you need to stop it by Ctrl + C and/ or can use it as systemd watcher daemon.

It uses stat for wide compatibility but can enable inotifywatch to check a file change by an event.

Institute for Medical Education; University of Bern

📄 Source: https://git-repo.iml.unibe.ch/iml-open-source/onfilechange
📜 License: GNU GPL 3.0
📗 Docs: https://os-docs.iml.unibe.ch/onfilechange/

Why?

You can use it to trigger actions that are not allowed by another user.

Scenario:

A web developer has access with a non privileged user to maintain an application … and on an update you want to allow him to restart the web service without sudo permissions.

Start the onfilechange to watch a defined file as root:

onfilechange.sh -f /var/www/touch2restart_httpd -c "systemctl restart httpd"

Or you can start a tool to process changed files in a watched directory: eg convert docs to PDF or videos.