Help understanding perl script

Hello,

A former sys admin placed this script on one of our boxes and it needs to be adjusted, but I'm not familiar with perl. Can someone help break this down for me? I'm particularly interested in the -mtime function. What's the time frame being referenced here.

open(HD,"/usr/local/src/files.txt");
system("/bin/rm -f /tmp/text.txt");

$line = <HD>;

while($line) {

  @ar=split(/\s+/,$line);
  chomp($ar[1]);
  print("$ar[0]\n");
  system("/bin/find $ar[0] -mtime $ar[1] -type f -print >> /tmp/text.txt");
  system("/bin/find $ar[0] -mtime $ar[1] -type f -exec rm -f  \{\} \\\; >> /tmp/text.txt");
  $line = <HD>

It is kind of hard to answer a question like that without seeing the contents of /usr/local/src/files.txt , but the time range would be specified by the 2nd "field" in that file.

Ah, I see. So it's calling that file and using the 2nd field to obtain the value for -mtime. Nice. Many thanks for your response.

---------- Post updated at 04:11 PM ---------- Previous update was at 03:41 PM ----------

If I wanted to exclude files with a certain extension from being removed, how can I add to this script to do this?

Change:

  system("/bin/find $ar[0] -mtime $ar[1] -type f -print >> /tmp/text.txt");
  system("/bin/find $ar[0] -mtime $ar[1] -type f -exec rm -f  \{\} \\\; >> /tmp/text.txt");

to:

  system("/bin/find $ar[0] ! -name '*.ext' -mtime $ar[1] -type f -print >> /tmp/text.txt");
  system("/bin/find $ar[0] ! -name '*.ext' -mtime $ar[1] -type f -exec rm -f  \{\} \\\; >> /tmp/text.txt");

where ext is the filename extension that appears on files you want to exclude from the list of files to be removed.

Can't a single find execute several actions ?

Yes.

And, I'm not sure what output from rm -f is intended to be captured in /tmp/text.txt either. With -f there won't be any file not found errors, and even if there were, they would be written to stderr instead of stdout.

It might be better if those two lines were replaced by the single line:

  system("/bin/find $ar[0] ! -name '*.ext' -mtime $ar[1] -type f -print -exec rm -f  \{\} \\\; >> /tmp/text.txt 2>&1");

but I don't know if the author of this thread wants find and rm diagnostics to be on the screen or captured in the log file.