Make Directory/File List

mkdirlist.pl is a simple Perl script to generate a PIKT directory or file list objects file (see, for example, dirs_system_redhat_linux_objects.cfg).

As with other scripts, we source mkdirlist.pl from the programs.cfg PIKT configuration file (or perhaps a mkdirlist_programs.cfg #include file; not shown).  The end-use, target script follows.

#!/usr/bin/perl

# mkdirlist.pl - make directory/file list objects file
#
#   $ARGV[0] refers to a type, either "d" for directories, or "f" for files
#            within the specified directories
#   $ARGV[1] refers to a quoted list of directories
#
#   for example:
#
#   mkdirlist.pl d "/bin /boot /dev /etc [...] /usr /var"

$t = $ARGV[0];
$d = $ARGV[1];

open(PASSWD, "/etc/passwd");
while (<PASSWD>) {
  /^([^:]+):[^:]+:(\d+):/;
  $user{$2} = $1;
}
close(PASSWD);

open(GROUP, "/etc/group");
while (<GROUP>) {
  /^([^:]+):[^:]+:(\d+):/;
  $group{$2} = $1;
}
close(GROUP);

open(FIND, "/usr/bin/find $d -type $t -exec /bin/ls -ld {} \\; |");
while (<FIND>) {
  #print "$_";
  chomp;
  /^(\S+)\s.+\s(\S+)$/;
  $m = $1;
  $f = $2;
  @s = stat($f);
  printf "%s %s %o %s %s %s %s\n",
         $f, $m, $s[2] & 07777, $s[4], $s[5], $user{$s[4]}, $group{$s[5]};
}
close(FIND);

exit 0;

So, you might make directory and file list objects files (on a Red Hat Linux system) as follows:

# /pikt/lib/programs/mkdirlist.pl d "/bin /boot /dev /etc ... /usr /var" >
  /pikt/lib/configs/objects/adm/dirs_system_redhat_linux_objects.cfg
# /pikt/lib/programs/mkdirlist.pl f "/bin /boot /dev /etc ... /usr" >
  /pikt/lib/configs/objects/adm/files_system_redhat_linux_objects.cfg

Note that some additional cleanup of the script output may be required.

For more examples, see Samples.

 
Home | FAQ | News | Intro | Samples | Tutorial | Reference | Software
Developer's Notes | Licensing | Authors | Pikt-Users | Pikt-Workers | Related Projects | Site Index | Privacy Policy | Contact Us
Page best viewed at 1024x768 or greater.   Page last updated 2018-01-02.   This site is PIKT® powered.
Copyright © 1998-2018 Robert Osterlund. All rights reserved.
Home FAQ News Intro Samples Tutorial Reference Software
PIKT Logo
PIKT Page Title
View sample
core file
deletion
Pikt script