0

これは今のところ私を困惑させているので、長い時間とたくさんのコーヒーを飲んだ後、私が知っている最高のコーディングコミュニティに助けを求めています.

基本的に、先に進む前にファイルがサーバーに存在しなくなるのを待つための perl スクリプトが必要です。すべてのスクリーンセッションが終了するのを待つことを実際に検討しています(/ var/run/screenが空のディレクトリになる)。

#!/usr/bin/perl
my $directory="/root/screens";

opendir(DIR, $directory) or die "couldn't open $directory: $!\n";
my @files = readdir DIR;
closedir DIR;

foreach (@files){

        while (-e $_) {
        print "$directory has $_ existing\n";
        sleep 1;
        }
}

Ex Dir.

  total 8 
  drwxr-xr-x.  2 root root 4096 Oct 11 22:58 ./ 
  drwxr-x---. 17 root root 4096 Oct 11 05:33 ../
  -rw-r--r--.  1 root root    0 Oct 11 22:58 S-root
  -rw-r--r--.  1 root root    0 Oct 11 22:58 S-root1

上記は明らかに機能しませんが、Google でこれを行う良い方法が見当たらず、長い 1 日でした。

4

5 に答える 5

0
#!/usr/bin/perl

my $directory="/root/screens";

opendir(DIR, $directory) or die "couldn't open $directory: $!\n";
@files = readdir DIR;
closedir DIR;

while (@files > 2) ### If @files have more than 2 items. 
{
opendir(DIR, $directory) or die "couldn't open $directory: $!\n";
@files = readdir DIR;
closedir DIR;
sleep (1);
}

print "Directory is now empty and loop has ended";

常に ./ と ../ があるため、@files には常に 2 つの項目があることに注意してください。

于 2013-10-19T11:23:24.593 に答える