-
Hahn Axel (hahn) authoredHahn Axel (hahn) authored
onfilechange
A Shell script that watches a given fileobject or multiple fileobjects (=files or directories). If one of the watched fileobject changes then a given command will be exxecuted. 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
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"