Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 0.98 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use POSIX;
  6.  
  7. $| = 1;
  8.  
  9. my $running = 0;
  10. my $permitted = 10;
  11.  
  12. sub processCompleted()
  13. {
  14.   while (waitpid(-1, WNOHANG) > 0)
  15.   {
  16.     $running--;
  17.   }
  18. }
  19.  
  20. # signal processing
  21. $SIG{CHLD} = \&processCompleted;
  22.  
  23. my $file = 'domaintmp/domainsfull';
  24. open FILE, '<', $file or die "Could not open $file\n";
  25. while (my $line = readline FILE)
  26. {
  27.   if ($running < $permitted)
  28.   {
  29.     my $pid = fork();
  30.     if ($pid)
  31.     {
  32.       # parent
  33.       $running++;
  34.     }
  35.     elsif ($pid == 0)
  36.     {
  37.       # child
  38.       my $tmpfile = "/tmp/domain-check.$$";
  39.       open TMPFILE, '>', $tmpfile;
  40.       print TMPFILE $line;
  41.       close TMPFILE;
  42.       my $command = "/home/simon/ssl-check.sh -i -f $tmpfile >> domaintmpout/$$.log 2>&1";
  43.       print "$command\n";
  44.       system ($command);
  45.       unlink $tmpfile;
  46.       exit 0;
  47.     }
  48.   }
  49.   else
  50.   {
  51.     sleep 1;
  52.   }
  53. }
  54. close FILE;
  55.  
  56. while (waitpid(-1, WNOHANG) > 0)
  57. {
  58.   sleep 1;
  59. }
  60.  
  61. exit 0;