-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathqpeek
executable file
·163 lines (155 loc) · 3.8 KB
/
qpeek
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/perl -w
#
# qpeek: Peek into a job's output spool files
# Copyright 2006 Ohio Supercomputer Center
# Revision info:
# $HeadURL: https://svn.osc.edu/repos/pbstools/releases/pbstools-1.5/bin/qpeek $
# $Revision: 1.1 $
# $Date: 2007/09/20 12:40:29 $
#
# 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")
# -# Show only # lines of output
# -e Show the stderr file of the job
# -o Show the stdout file of the job
# -? Display help
$tool="cat";
$numlines="";
$suffix="OU";
if ( defined($ENV{"PBS_HOME"}) )
{
$spool=$ENV{"PBS_HOME"};
}
else
{
@defaults=("/usr/spool/PBS",
"/var/spool/pbs",
"/var/spool/torque",
"/var/spool/batch/pbs",
"/var/spool/batch/torque",
"/var/spool/batch/pbs-piv",
"/var/spool/batch/pbs-ipf",
"/opt/torque",
".",
);
foreach $dir ( @defaults )
{
if ( -d $dir )
{
$spool=$dir;
last;
}
}
}
if ( !defined($spool) )
{
die "Unable to find PBS spool directory!\n";
}
$pbsserver=`cat $spool/server_name` ||
die "Unable to find PBS server name!\n";
chop($pbsserver);
# hack for sloppy admins who don't put the full hostname
# in $PBS_HOME/server_name
if ( $pbsserver =~ /:/ )
{
($host,$port) = split(/:/,$pbsserver);
@server=gethostbyname($host);
$pbsserver=$server[0].":".$port;
}
else
{
@server=gethostbyname($pbsserver);
$pbsserver=$server[0];
$host=$server[0];
}
while ( $#ARGV>=0 && $ARGV[0] =~ /^[-+].*/ )
{
if ( $ARGV[0] eq "-c" )
{
$tool="cat";
}
elsif ( $ARGV[0] eq "-h" )
{
$tool="head";
}
elsif ( $ARGV[0] eq "-t" )
{
$tool="tail";
}
elsif ( $ARGV[0] =~ /^[-+][0-9]*(f)?$/ )
{
$tool="tail";
$numlines=$ARGV[0];
}
elsif ( $ARGV[0] eq "-e" )
{
$suffix="ER"
}
elsif ( $ARGV[0] eq "-o" )
{
$suffix="OU"
}
elsif ( $ARGV[0] eq "-?" || $ARGV[0] =~ "-(-)?help" )
{
print STDERR <<EOF;
qpeek: Peek into a job's output spool files
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")
-<num>f Show only the last <num> lines and keep listening ("tail -<num>f")
+0f Show all of the file and keep listening ("tail +0f")
-# Show only # lines of output ("tail -<num>")
-e Show the stderr file of the job
-o Show the stdout file of the job (default)
-? Display this help message
EOF
exit;
}
else
{
print STDERR "qpeek: Unrecognized option $ARGV[0] ignored\n";
}
shift(@ARGV);
}
if ( $#ARGV>=0 )
{
$jobid=shift(@ARGV);
$jobid=~s/\.[A-z0-9.:]+$//;
}
else
{
die "No jobid given!\n";
}
$node=&mothersuperior($jobid);
die "Job $jobid is not running!\n" if ( $node eq "" );
# chop to magic pbs length
$jobname = "$jobid.$pbsserver";
$jobname =~ s/(.{11}).*/$1/;
exec "ssh -n $node $tool $numlines $spool/spool/$jobname.$suffix\n";
sub mothersuperior
{
local($jobid,$node);
$jobid=$_[0];
$node="";
open(QSTAT,"qstat -f $jobid |");
while ( <QSTAT> )
{
chop;
if ( $_ =~ /exec_host/ )
{
($keyword,$node)=split(/=/);
$node=~s:/[0-9]+[A-z0-9/+.-]*::;
$keyword="";
}
}
close(QSTAT);
$node;
}