LJ Archive

Listing 5. pbsdcp

#!/usr/bin/perl
# pbsdcp -- Distributed copy command for the PBS
#  environment
# Copyright 2000, Ohio Supercomputer Center
#
# Usage:  pbsdcp [options] srcfile [...srcfiles...]
#  target
#
# Options:
#  -h   print a help message
#  -p   preserve modification times and permissions
#  -r   recursive copy
if ( ! $ENV{"PBS_ENVIRONMENT"} ||
     ( $ENV{"PBS_ENVIRONMENT"} ne "PBS_BATCH" &&
       $ENV{"PBS_ENVIRONMENT"} ne
        "PBS_INTERACTIVE" ) ||
     $ARGV[0] eq "-h" || $#ARGV < 1 )
{
    if ( ! $ENV{"PBS_ENVIRONMENT"} ||
         ( $ENV{"PBS_ENVIRONMENT"} ne "PBS_BATCH" &&
           $ENV{"PBS_ENVIRONMENT"} ne
            "PBS_INTERACTIVE" ) )
    {
        warn "$0:  Not running withing a PBS job,
         exiting.\n\n";
    }
    print <<EOH
$0 -- Distributed copy command for the PBS environment
Usage:  pbsdcp [options] srcfile [...srcfiles...]
         target
Options:
  -h   print this help message
  -p   preserve modification times and permissions
  -r   recursive copy
EOH
}
else
{
    $target=pop(@ARGV);
    if ( -e $ENV{'PBS_NODEFILE'} )
    {
        open(NODES,"uniq ".$ENV{'PBS_NODEFILE'}." |");
        @node=<NODES>;
        chop(@node);
        for ( $i=0 ; $i<=$#node; $i++ )
        {
            if ( ($pid[$i]=fork)==0 )
            {
                exec("rcp @ARGV $node[$i]:$target");
            }
        }
        for ( $i=0 ; $i<=$#node; $i++ )
        {
            waitpid($pid[$i],0);
        }
    }
    else
    {
        exec("cp @ARGV $target");
    }
}
LJ Archive