#!/usr/bin/perl # # spool-jobscripts -- copy newly created job scripts to a spool directory # Copyright 2006 Ohio Supercomputer Center # # License: GNU GPL v2; see ../COPYING for details. # Revision info: # $HeadURL$ # $Revision$ # $Date$ # # Not intended to be invoked directly, but rather by dnotify (or the moral # equivalent thereof): # dnotify -b -p 1 -C $PBS_HOME/server_priv/jobs -e /usr/local/sbin/spool-jobscripts '{}' use strict; # my spool dir my $spooldir="/tmp/scripts"; if ( ! -d $spooldir ) { mkdir($spooldir) || die "Unable to create $spooldir: $!"; chmod(0700,$spooldir); } elsif ( ! -w $spooldir ) { die "Unable to write to $spooldir: $!"; } # sanity check $ARGV[0] my $pbsjobdir=$ARGV[0]; if ( ! defined($pbsjobdir) ) { $pbsjobdir = "/var/spool/torque/server_priv/jobs"; } # get list of script files opendir(DIR,$pbsjobdir) || die "Can't opendir ".$pbsjobdir.": $!"; my @scriptfiles = grep { /\.SC$/ && -f "$pbsjobdir/$_" } readdir(DIR); closedir(DIR); # for each script file, copy it to the spool directory if it's not already # there my @file; my @newfile; foreach my $scriptfile (@scriptfiles) { if ( -e "$pbsjobdir/$scriptfile" && ! -e "$spooldir/$scriptfile" ) { push(@file,"$pbsjobdir/$scriptfile"); push(@newfile,"$spooldir/$scriptfile"); } } # copy files to spool dir if ( $#file>=0 ) { unshift(@file,"cp"); push(@file,"$spooldir"); system("/bin/cp",@file); } # fork/exec jobscript-to-db; don't wait for completion if ( $#newfile>=0 ) { my $pid=fork(); if ( $pid==0 ) { unshift(@newfile,"jobscript-to-db"); exec("/usr/local/sbin/jobscript-to-db",@newfile); exit(0); } }