Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I want to write a program — a daemon if you will — that instantaneously automatically saves when any changes are done to my ZFS filesystem (what was the command used, the output, the action it performed). It needs to save instantaneously as soon as the `zfs` or `zpool` command is issued, that's I don't want to use cron/systemd timers, it has to update in real-time. How can I do this? Please recommend me modules.
  • Comment on How to instantaneously automatically save

Replies are listed 'Best First'.
Re: How to instantaneously automatically save
by jo37 (Curate) on Jan 14, 2024 at 16:47 UTC

    I'm not sure if your requirement is specific to ZFS or of more general nature and I don't know what OS you are using. On Linux, there is Inotify that will trigger callbacks when files are accessed/changed. There is a Perl interface: Linux::Inotify2, though I don't know if it is able to handle directories recursively.

    Greetings,
    -jo

    $gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$
Re: How to instantaneously automatically save
by Anonymous Monk on Jan 14, 2024 at 06:56 UTC
    Ok, so let me rephrase my question: How do I make a perl program that listens for whenever `zpool`and `zfs` command is used and saves it in database? Thanks in advance.
      EDIT: whenever `zpool` and `zfs`is used in the terminal

        The easiest way is to rename the zfs and zpool commands to something else (zfs.org?) and name your new programs zfs and zpool.

        Alternatively, set up shell aliases for the users using these commands.

        Alternatively, learn about what APIs ZFS offers to know about what zfs and zpool do or change, and listen to these API calls.

Re: How to instantaneously automatically save
by Anonymous Monk on Jan 17, 2024 at 08:54 UTC
    It's OP here. Suppose I'm on Linux using ext4 and do `resize2fs` to either shrink or grow the filesystem, how does my perl program capture on the fly how much the filesystem was shrank or grown into? I'm thinking I'd have to make my program listen/watch the Journalling API calls (https://www.kernel.org/doc/html/v4.19/filesystems/index.html#the-linux-journalling-api), right? What module would I use to listen/watch the API calls constantly so that I can capture the information from the journal instantaneously as soon as the shrink or grow is done? Thanks in advance.