ASPL User Guide v 1.00
© 2025 Bassem W. Jamaleddine


20. 1
   Monitoring Changes in UNIX Directories

 

Monitor Changes in UNIX Filesystem

ELEMENTS-GROUPING-CLASS: POSIX

Script to monitor directory: monitordir.aspl

Sample workspace: MONITORDIRCHANGES

Globing the Directory

      mydir = ggdir(dir,/tmp/aaaa1)       where mydir is a set variable

Interrogating the Set Variable

      ?10,2   mydir       interrogate mydir 10 times with 2 seconds delay

Show changes in mydir

      playchanges   mydir

how to monitor dirctories on the UNIX filesystem, monitor changes in subdirectories and files

●  Monitoring Changes in UNIX Directories

You can monitor a UNIX directory using ASPL, either by using the script monitordir.aspl or by issuing commands directly within the ASPL console. In what follows, we show two examples on how to monitor a directory: the first example uses the script monitordir.aspl, and the second example uses the ASPL console started with the sample workspace MONITORDIRCHANGES.

 

Script monitordir.aspl to Detect Changes in UNIX Directories

In this example we use the following script monitordir.aspl to monitor the directory /tmp/aaaa1 where several changes occured.

 -LIS- Listing. 20.1.1   [LISTING monitordir.aspl][Script monitordir.aspl]
(raw text)
1.     #!/usr/bin/env  aspl 
2.     #ENVARG= -wsname TRANSIENT -groupingclass POSIX
3.     
4.     ;;***********************************************************************
5.     ;;   monitordir.aspl
6.     ;;   
7.     ;;   Copyright © 2021-2025 Bassem W. Jamaleddine
8.     ;;   All rights reserved.
9.     ;;   
10.    ;;***********************************************************************
11.    
12.    endScriptIfShellArgsLessThan 2
13.    
14.    printblock MONITORING DIRECTORY $1 $2 TIMES WITH DELAY OF $3 SECONDS
15.    mydir = ggdir(dir,$1)
16.    sleep 2
17.    ?$2,$3 mydir
18.    @ mydir
19.    intermittentarc 1
20.    printblock PLAY INTERMITTENT CHANGES IN DIRECTORY $1
21.    playchanges mydir
22.    printblock SHOW SIMILARITY BETWEEN INTERMITTENT CHANGES
23.    playsim sim`fflz mydir
24.    printblock PLAY INTERMITTENTLY THE UNION WHERE CHANGES ARE DETECTED 
25.    playop ,gD,`ks~  mydir
26.    printblock PLAY INTERMITTENTLY THE UNION WHERE CHANGES ARE DETECTED 
27.    playop ,gU`ks~  mydir
28.    printblock SHOW THE UNION OF ALL INSTANCES AT ONCE
29.    ,gU  @mydir
30.    
31.    ;; Show basic changes in elements and subdirectories WITHOUT attributes
32.    playop ,gD mydir
33.    
34.    ;; of course you can select the desirec attributes by using ks 
35.    ;; ks uid gid mtime chksum ppdd ffl aelm
36.    
37.    printblock SHOW CHANGES IN THE DIFFERENTIAL GROUP VARIABLE mydir
38.    ,f@`ks~  mydir
39.    ,d@`ks~  mydir
40.    ,g@`ks~  mydir
41.    
42.    ;;intermittentarc 1
43.    ;;playop ,gU`ks~  mydir
44.    
45.    ;;intermittentcontinuous 1
46.    ;;playop ,gU  mydir
47.    ;;playop ,gU`ks~ mydir
48.    ;;playop ,gU`c~  mydir
49.    
50.    endscript
51.    
52.    __END__
53.    
54.    $00 must be followed by three arguments: directory-to-monitor  iterations 
      seconds 
55.    
56.       Monitor directory /tmp/aaaa1 looping 7 times with 4 seconds delay
57.          $00 "/tmp/aaaa1"  7  4

ASPL(C) 2025 Bassem Jamaleddine

 

Script monitordir.aspl to Detect Changes in UNIX Directories

The following command monitor the directory /tmp/aaaa1 in a loop iterating seven times with a delay of four seconds in between each ieration.

monitordir.aspl /tmp/aaaa1 7 4

To show the resulting output of the script, we captured it in some sample workspace DIR1234 and show it in the following display.

viewme

 -TC- Display. 20.1.1   [UG-monitordir-aspl-links]
run for UG-monitordir-aspl-links.html

 

Differential Operations on a UNIX Directory
Shown below the commands to monitor the directory /tmp/testdir1 from within an ASPL session. To demonstrate the operations, we start ASPL by loading the sample workspace MONITORDIRCHANGES whose grouping class is POSIX, then we issue various set operations to reveal the changes in the directory /tmp/testdir1.

We create the set variable mydir in which we globed the directory /tmp/testdir1 by calling the GG-function ggdir(). We slept two seconds, then immediately we issued the command ?10,2 mydir to interrogate mydir in an iterative loop: looping ten times with a delay of two seconds between each iteration. The iterations in here are within the same ASPL statement: checking for any change in the dataset associated with mydir; should any change be detected then the group is updated, and the old dataset is archived. The command @ mydir printed the the differential set variable mydir. We used various differential group operators to show the changes in the directory /tmp/testdir1. The command playchanges mydir revealed the intermittent changes in the directory, and it showed the rate of changes in the directory.

 

Differential Operations on a UNIX Directory

aspl MONITORDIRCHANGES
    (start ASPL loading the sample workspace MONITORDIRCHANGES)

①  aspl> mydir = ggdir(dir,/tmp/testdir1); sleep 2; ?10,2 mydir
    glob the directory /tmp/testdir1 and monitor it

②  aspl> @ mydir
    print the differential set variable mydir

③  aspl> g@,`ks~ mydir
    use the differential group operator g@ to display the differences in the differential set variable mydir

④  aspl> d@,`ks~ mydir
    display the differences in the subgroups using the differential group operator d@

⑤  aspl> f@,`ks~ mydir
    display the differences in the elements using the differential group operator f@

⑥  aspl> playchanges mydir
    display the changes in the differential set variable mydir, and show rate of change

⑦  aspl> intermittentarc 1
    set intermittance to 1

⑧  aspl> playchanges mydir
    display the changes intermittently between the instances registered in the differential set variable mydir

⑨  aspl> intermittentcontinuous

⑩  aspl> intermittentcontinuous 1
    set intermittentcontinuous to 1

⑪  aspl> playop gD,`ks~ mydir
    play of the operator of symmetric group difference on the differential set variable mydir

⑫  aspl> gD,`ks~ @mydir
    display the symmetric group difference (tick for changes in ks vector) on all the instances registered in mydir

⑬  aspl> gD, @mydir
    display the symmetric group difference on all the instances registered in mydir

This example is shown in the following terminal.

viewme

 -TC- Display. 20.1.2   [UG-MONITORDIRCHANGES-Sample-links]
run for UG-MONITORDIRCHANGES-Sample-links.html