ASPL Manual v 1.00
© 2024 by SetSphere.COM


12-3

   Script dirdiff.pl

Comparing directories and files on the UNIX system is easy with ASPL. The following script takes multiple directories located on multiple UNIX hosts and shows their differences. Use the script dirdiff.pl in a Linux cloud to compare directories across your host servers.

       [Top Text]

 -L- Listing. 12.3.1   [LISTING dirdiff-pl-numln.txt][Script dirdiff.pl]
(raw text)
1.     #!/usr/bin/perl
2.     
3.     use strict;
4.     use warnings;
5.     
6.     # dirdiff.pl host1:/dir1  host2:/dir2  ..
7.     
8.     usage() unless @ARGV > 1;
9.     sub usage { print join "",<DATA>; exit; }
10.    
11.    my @hostdirs = @ARGV;;
12.    
13.    my $interpreter = "aspl -groupingclass POSIX -wsname TRANSIENT -singlepass -dm 2";
14.    
15.    # NOTE shebang arguments take priority over interpreter preceding -STDIN
16.    #my $shebang = "#!/opt/ASPLv1.00/bin/aspl -groupingclass POSIX -wsname TRANSIENT 
      -singlepass -dm 3"; 
17.    my $shebang = "";
18.    my $s = "$shebang\n";
19.    
20.    $s .= "timeout 120\n";
21.    $s .= "displayoff\n";
22.    
23.    my @vnames;
24.    my $localhost = `hostname`;
25.    my $vcnt = 0;
26.    chomp $localhost;
27.    foreach my $hostdir (@hostdirs) {
28.        die "BAD FORMAT AS THE LIST SHOULD CONSIST OF host1:dir1 host2:dir2 ..\n" 
      unless $hostdir =~ /^(.*?)\:(.*)$/; 
29.        my ($host,$dir) = ($1,$2);
30.        my $vname = "v" . ++$vcnt;
31.        push(@vnames,$vname);
32.        if ($localhost =~ /^$host([\.]\w){0,}/i) {
33.            $s .= "print GATHERING DIRECTORY $dir ON $host\n";
34.            $s .= "$vname = ggdir(grp1,$host,dir,$dir)\n";
35.        }
36.        else {
37.            $s .= "print GATHERING DIRECTORY $dir ON REMOTE $host\n";
38.            $s .= "$vname = ggdirR(grp1,$host,hostname,$host,dir,$dir)\n";
39.        }
40.    }
41.    $s .= "
42.    displayon\
43.    ks mtime chksum size ppdd ffl
44.    ,gU @vnames
45.    sim @vnames
46.    v
47.    ";
48.    
49.    open(ASPL, "| $interpreter -STDIN") or die "ERROR OPENING A PIPE TO aspl: $! \n";
50.    print ASPL $s;
51.    close ASPL;
52.    
53.    __END__
54.    
55.      COMPARE ENV VARIABLES FOR HOST MACHINES IN A CLOUD
56.    
57.       dirdiff.pl must be followed by a list of hosts diretcory a such host1:dir1 
      host2:dir2 
58.    
59.      Use ASPL run time interpreter to compare the directories across machines
60.      in a cloud environment.
61.    
62.         $0  host1:dir1 host2:dir2  ..  hostN:dirN
63.      
64.       the directories must be specified and available on the host machines.
65.    
66.       at least pair of hostdir must be specified. The script will check
67.       if the hostname specified is the local hostname, in which case
68.       the PATH of the current host is gathered, and any other host name
69.       is treated as a remote host. The remote hosts must be ssh configured
70.       and ssh'able from the machine where this script is executed
71.       otherwise the script will fail to gather the directory on the remote host. 
72.    
73.      Example:
74.       $0  mm01:/sbin  vienna:/usr/sbin
75.    

ASPL(C) 2024 Bassem Jamaleddine


       Figure dirdiff-pl.png
full view

Image File

 -F- Fig. 12.3.1   [COMPARING DIRECTORIES IN A CLOUD]
ASPL (C) 2024 Bassem Jamaleddine


       Figure dirdiff-pl-2.png
full view

Image File

 -F- Fig. 12.3.2   [COMPARING DIRECTORIES IN A CLOUD 2]
ASPL (C) 2024 Bassem Jamaleddine






This example is shown in the following terminal.