#!/usr/bin/perl # # qpeek: Peek into a job's output spool files # Copyright 2001, 2006, 2007, 2016 Ohio Supercomputer Center # Copyright 2008, 2010 Adaptive Computing # # License: GNU GPL v2; see ../COPYING for details. # Revision info: # $HeadURL$ # $Revision$ # $Date$ # # Usage: qpeek [options] JOBID # # Options: # -c Show all of the output file ("cat", default) # -h Show only the beginning of the output file ("head") # -t Show only the end of the output file ("tail") # -f Show only the end of the file and keep listening ("tail -f") # -e Show the stderr file of the job # -o Show the stdout file of the job # # -ssh Use the ssh command to remote access the mother superior node # -rsh Use the rsh command to remote access the mother superior node # -spool= Specify the location of the spool directory, defaults to /opt/torque # -host= The name of the host to use in the filename for the jobs stdout or stderr # # -help|? Display help message use strict; use warnings; use Getopt::Long qw(:config bundling); MAIN: { # Options Variables my $tool = "cat"; my $rsh_cmd = "rsh"; my $help = 0; my $o = 0; my $e = 0; my $host_in_jobid = 1; my $spool; my $host; GetOptions( 'c' => sub { $tool = "cat" }, 'f' => sub { $tool = "tail -f" }, 'h' => sub { $tool = "head" }, 't' => sub { $tool = "tail" }, 'e' => \$e, 'o' => \$o, 'ssh' => sub { $rsh_cmd = "ssh" }, 'rsh' => sub { $rsh_cmd = "rsh" }, 'spooldir|spool=s' => \$spool, 'host=s' => \$host, 'help|?' => \$help, ); if ( !defined($spool) && defined($ENV{'PBS_HOME'}) ) { $spool = $ENV{'PBS_HOME'}; } elsif ( !defined($spool) ) { $spool = "/opt/torque"; } if ( !defined($host) && -r "$spool/server_name" ) { $host = `cat $spool/server_name`; chomp($host); } elsif ( !defined($host) ) { $host = "set_the_host"; } # Set OU as the default spool suffix $o = 1 unless ($o or $e); # Print help printHelp() if $help; # Get the job id my $jobid = shift(@ARGV) || die "No job id given!"; $jobid =~ s/\.[A-z0-9.]+$//; die "No jobid given!\n" if ($jobid eq ""); # Get the mother superior node my $node = &motherSuperior($jobid); die "Job $jobid is not running!\n" if ($node eq ""); # Format and run the command my $cmd = "$rsh_cmd $node $tool"; if ( $host_in_jobid==1 ) { $cmd .= " $spool/spool/$jobid.$host.OU" if $o; $cmd .= " $spool/spool/$jobid.$host.ER" if $e; } else { $cmd .= " $spool/spool/$jobid.OU" if $o; $cmd .= " $spool/spool/$jobid.ER" if $e; } $cmd .= "\n"; exec $cmd; exit 0; } # END MAIN #------------------------------------------------------------------------------ # printHelp #------------------------------------------------------------------------------ sub printHelp #() { print STDERR < Specifiy the location of the spool directory, defaults to /opt/torque -host= The name of the host to use in the filename for the jobs stdout or stderr -help|? Display help message EOF exit 0; } # END sub printHelp #() #------------------------------------------------------------------------------ # motherSuperior #------------------------------------------------------------------------------ sub motherSuperior #($) { my $jobid; my $node; my $keyword; $jobid = $_[0]; $node = ""; open(QSTAT, "qstat -f $jobid |"); while () { chop; if ($_ =~ /exec_host/) { ($keyword, $node) = split(/=/); $node =~ s:/[0-9]+[A-z0-9/+]*::; } } return $node; } # END sub motherSuperior #($)