A simple perl script, to wait till a given number of files stop
changing, is described below:
-
I needed today a script, that monitors on a given number of files, for no change by
a running program. When all files stop to change, the program is killed.
This was targeted to a program, which
lacks the ability to close itself, when done or in idle.
-
The script is invoked by the following way:
perl ~/bin/wait_while_file_is_changed.pl veloce_transcript logs/moca2_chk.emu.log ; bkill 822525
The first part fires the perl script with as much files as the user wishes to
monitor and when the script detects no file change, it stops. Once stopped, the
other command is executed.
-
The script is listed below:
#!/bin/perl
$flg=1;
$cnt=0;
while($flg == 1) {
foreach $file ( @ARGV ) {
$cmd="ls -l " . $file;
$f_date_last=`$cmd`;
sleep 120;
$f_date_curr=`$cmd`;
$ix=index($f_date_last, $f_date_curr);
if($ix == 0) {$cnt++;}
$f_date_last=$f_date_curr;
}
$N=$#ARGV + 1;
print("$cnt $N\n");
if($cnt == $N) {
$flg=0;
}
$cnt=0;
}#while
|