diff --git a/contribs/torque/qalter.pl b/contribs/torque/qalter.pl old mode 100644 new mode 100755 index e5ac6a462b24809f0fc0b0cf353683b3d25f4a4e..d8c9fbed5f3d99655169761c4a09111fccb39a5c --- a/contribs/torque/qalter.pl +++ b/contribs/torque/qalter.pl @@ -1,232 +1,232 @@ -#! /usr/bin/perl -w -############################################################################### -# -# qalter - PBS wrapper for changing job status using scontrol -# -############################################################################### - -use strict; -use FindBin; -use Getopt::Long 2.24 qw(:config no_ignore_case); -use lib "${FindBin::Bin}/../lib/perl"; -use autouse 'Pod::Usage' => qw(pod2usage); -use Slurm ':all'; -use Slurmdb ':all'; # needed for getting the correct cluster dims -use Switch; - -# ------------------------------------------------------------------ -# This makes the assumption job_id will always be the last argument -# ------------------------------------------------------------------- -my $job_id = $ARGV[$#ARGV]; -my ( - $err, - $new_name, - $output, - $rerun, - $resp, - $slurm, - $man, - $help -); - -# Remove this -my $scontrol = "/usr/slurm/bin/scontrol"; - -# ------------------------------ -# Parse Command Line Arguments -# ------------------------------ -GetOptions( - 'N=s' => \$new_name, - 'r=s' => \$rerun, - 'o=s' => \$output, - 'help|?' => \$help, - 'man' => \$man - ) - or pod2usage(2); - -pod2usage(0) if $help; - -if ($man) -{ - if ($< == 0) # Cannot invoke perldoc as root - { - my $id = eval { getpwnam("nobody") }; - $id = eval { getpwnam("nouser") } unless defined $id; - $id = -2 unless defined $id; - $< = $id; - } - $> = $<; # Disengage setuid - $ENV{PATH} = "/bin:/usr/bin"; # Untaint PATH - delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; - if ($0 =~ /^([-\/\w\.]+)$/) { - $0 = $1; # Untaint $0 - } else { - die "Illegal characters were found in \$0 ($0)\n"; - } - pod2usage(-exitstatus => 0, -verbose => 2); -} - -# ---------------------- -# Check input arguments -# ---------------------- -if (@ARGV < 1) { - pod2usage(-message=>"Missing Job ID", -verbose=>0); -} else { - $slurm = Slurm::new(); - $resp = $slurm->get_end_time($job_id); - if (not defined($resp)) { - pod2usage(-message=>"Job id $job_id not valid!", -verbose=>0); - } - if ((not defined($new_name)) and (not defined($rerun)) and (not defined($output))) { - pod2usage(-message=>"no argument given!", -verbose=>0); - } -} - -# -------------------------------------------- -# Use Slurm's Perl API to change name of a job -# -------------------------------------------- -if ($new_name) { - my %update = (); - - $update{job_id} = $job_id; - $update{name} = $new_name; - if (Slurm->update_job(\%update)) { - $err = Slurm->get_errno(); - $resp = Slurm->strerror($err); - pod2usage(-message=>"Job id $job_id name change error: $resp", -verbose=>0); - exit(1); - } -} - -# --------------------------------------------------- -# Use Slurm's Perl API to change the requeue job flag -# --------------------------------------------------- -if ($rerun) { - my %update = (); - - $update{job_id} = $job_id; - if (($rerun eq "n") || ($rerun eq "N")) { - $update{requeue} = 0; - } else { - $update{requeue} = 1; - } - if (Slurm->update_job(\%update)) { - $err = Slurm->get_errno(); - $resp = Slurm->strerror($err); - pod2usage(-message=>"Job id $job_id requeue error: $resp", -verbose=>0); - exit(1); - } -} - -# ------------------------------------------------------------ -# Use Slurm's Perl API to change Comment string -# Comment is used to relocate an output log file -# ------------------------------------------------------------ -if ($output) { - # Example: - # $comment="on:16337,stdout=/gpfsm/dhome/lgerner/tmp/slurm-16338.out,stdout=~lgerner/tmp/new16338.out"; - # - my $comment; - my %update = (); - - # --------------------------------------- - # Get current comment string from job_id - # --------------------------------------- - my($job) = $slurm->load_job($job_id); - $comment = $$job{'job_array'}[0]->{comment}; - - # ---------------- - # Split at stdout - # ---------------- - if ($comment) { - my(@outlog) = split("stdout", $comment); - - # --------------------------------- - # Only 1 stdout argument add a ',' - # --------------------------------- - if ($#outlog < 2) { - $outlog[1] .= "," - } - - # ------------------------------------------------ - # Add new log file location to the comment string - # ------------------------------------------------ - $outlog[2] = "=".$output; - $comment = join("stdout", @outlog); - } else { - $comment = "stdout=$output"; - } - - # ------------------------------------------------- - # Make sure that "%j" is changed to current $job_id - # ------------------------------------------------- - $comment =~ s/%j/$job_id/g ; - - # ----------------------------------------------------- - # Update comment and print usage if there is a response - # ----------------------------------------------------- - $update{job_id} = $job_id; - $update{comment} = $comment; - if (Slurm->update_job(\%update)) { - $err = Slurm->get_errno(); - $resp = Slurm->strerror($err); - pod2usage(-message=>"Job id $job_id comment change error: $resp", -verbose=>0); - exit(1); - } -} -exit(0); - -############################################################################## - -__END__ - -=head1 NAME - -B<qalter> - alter a job name, the job rerun flag or the job output file name. - -=head1 SYNOPSIS - -qalter [-N Name] - [-r y|n] - [-o output file] - <job ID> - -=head1 DESCRIPTION - -The B<qalter> updates job name, job rerun flag or job output(stdout) log location. - -It is aimed to be feature-compatible with PBS' qsub. - -=head1 OPTIONS - -=over 4 - -=item B<-N> - -Update job name in the queue - -=item B<-r> - -Alter a job rerunnable flag. "y" will allow a qrerun to be issued. "n" disable qrerun option. - -=item B<-o> - -Alter a job output log file name (stdout). - -The job log will be move/rename after the job has B<terminated>. - -=item B<-?> | B<--help> - -brief help message - -=item B<-man> - -full documentation - -=back - -=head1 SEE ALSO - -qrerun(1) qsub(1) -=cut - +#! /usr/bin/perl -w +############################################################################### +# +# qalter - PBS wrapper for changing job status using scontrol +# +############################################################################### + +use strict; +use FindBin; +use Getopt::Long 2.24 qw(:config no_ignore_case); +use lib "${FindBin::Bin}/../lib/perl"; +use autouse 'Pod::Usage' => qw(pod2usage); +use Slurm ':all'; +use Slurmdb ':all'; # needed for getting the correct cluster dims +use Switch; + +# ------------------------------------------------------------------ +# This makes the assumption job_id will always be the last argument +# ------------------------------------------------------------------- +my $job_id = $ARGV[$#ARGV]; +my ( + $err, + $new_name, + $output, + $rerun, + $resp, + $slurm, + $man, + $help +); + +# Remove this +my $scontrol = "/usr/slurm/bin/scontrol"; + +# ------------------------------ +# Parse Command Line Arguments +# ------------------------------ +GetOptions( + 'N=s' => \$new_name, + 'r=s' => \$rerun, + 'o=s' => \$output, + 'help|?' => \$help, + 'man' => \$man + ) + or pod2usage(2); + +pod2usage(0) if $help; + +if ($man) +{ + if ($< == 0) # Cannot invoke perldoc as root + { + my $id = eval { getpwnam("nobody") }; + $id = eval { getpwnam("nouser") } unless defined $id; + $id = -2 unless defined $id; + $< = $id; + } + $> = $<; # Disengage setuid + $ENV{PATH} = "/bin:/usr/bin"; # Untaint PATH + delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; + if ($0 =~ /^([-\/\w\.]+)$/) { + $0 = $1; # Untaint $0 + } else { + die "Illegal characters were found in \$0 ($0)\n"; + } + pod2usage(-exitstatus => 0, -verbose => 2); +} + +# ---------------------- +# Check input arguments +# ---------------------- +if (@ARGV < 1) { + pod2usage(-message=>"Missing Job ID", -verbose=>0); +} else { + $slurm = Slurm::new(); + $resp = $slurm->get_end_time($job_id); + if (not defined($resp)) { + pod2usage(-message=>"Job id $job_id not valid!", -verbose=>0); + } + if ((not defined($new_name)) and (not defined($rerun)) and (not defined($output))) { + pod2usage(-message=>"no argument given!", -verbose=>0); + } +} + +# -------------------------------------------- +# Use Slurm's Perl API to change name of a job +# -------------------------------------------- +if ($new_name) { + my %update = (); + + $update{job_id} = $job_id; + $update{name} = $new_name; + if (Slurm->update_job(\%update)) { + $err = Slurm->get_errno(); + $resp = Slurm->strerror($err); + pod2usage(-message=>"Job id $job_id name change error: $resp", -verbose=>0); + exit(1); + } +} + +# --------------------------------------------------- +# Use Slurm's Perl API to change the requeue job flag +# --------------------------------------------------- +if ($rerun) { + my %update = (); + + $update{job_id} = $job_id; + if (($rerun eq "n") || ($rerun eq "N")) { + $update{requeue} = 0; + } else { + $update{requeue} = 1; + } + if (Slurm->update_job(\%update)) { + $err = Slurm->get_errno(); + $resp = Slurm->strerror($err); + pod2usage(-message=>"Job id $job_id requeue error: $resp", -verbose=>0); + exit(1); + } +} + +# ------------------------------------------------------------ +# Use Slurm's Perl API to change Comment string +# Comment is used to relocate an output log file +# ------------------------------------------------------------ +if ($output) { + # Example: + # $comment="on:16337,stdout=/gpfsm/dhome/lgerner/tmp/slurm-16338.out,stdout=~lgerner/tmp/new16338.out"; + # + my $comment; + my %update = (); + + # --------------------------------------- + # Get current comment string from job_id + # --------------------------------------- + my($job) = $slurm->load_job($job_id); + $comment = $$job{'job_array'}[0]->{comment}; + + # ---------------- + # Split at stdout + # ---------------- + if ($comment) { + my(@outlog) = split("stdout", $comment); + + # --------------------------------- + # Only 1 stdout argument add a ',' + # --------------------------------- + if ($#outlog < 2) { + $outlog[1] .= "," + } + + # ------------------------------------------------ + # Add new log file location to the comment string + # ------------------------------------------------ + $outlog[2] = "=".$output; + $comment = join("stdout", @outlog); + } else { + $comment = "stdout=$output"; + } + + # ------------------------------------------------- + # Make sure that "%j" is changed to current $job_id + # ------------------------------------------------- + $comment =~ s/%j/$job_id/g ; + + # ----------------------------------------------------- + # Update comment and print usage if there is a response + # ----------------------------------------------------- + $update{job_id} = $job_id; + $update{comment} = $comment; + if (Slurm->update_job(\%update)) { + $err = Slurm->get_errno(); + $resp = Slurm->strerror($err); + pod2usage(-message=>"Job id $job_id comment change error: $resp", -verbose=>0); + exit(1); + } +} +exit(0); + +############################################################################## + +__END__ + +=head1 NAME + +B<qalter> - alter a job name, the job rerun flag or the job output file name. + +=head1 SYNOPSIS + +qalter [-N Name] + [-r y|n] + [-o output file] + <job ID> + +=head1 DESCRIPTION + +The B<qalter> updates job name, job rerun flag or job output(stdout) log location. + +It is aimed to be feature-compatible with PBS' qsub. + +=head1 OPTIONS + +=over 4 + +=item B<-N> + +Update job name in the queue + +=item B<-r> + +Alter a job rerunnable flag. "y" will allow a qrerun to be issued. "n" disable qrerun option. + +=item B<-o> + +Alter a job output log file name (stdout). + +The job log will be move/rename after the job has B<terminated>. + +=item B<-?> | B<--help> + +brief help message + +=item B<-man> + +full documentation + +=back + +=head1 SEE ALSO + +qrerun(1) qsub(1) +=cut + diff --git a/contribs/torque/qrerun.pl b/contribs/torque/qrerun.pl old mode 100644 new mode 100755 index 2cc1c5419ddc132b00e38e2649c4594fdc908473..67b9681f0421e2943eb05f047c33e6ca63f804eb --- a/contribs/torque/qrerun.pl +++ b/contribs/torque/qrerun.pl @@ -1,134 +1,134 @@ -#! /usr/bin/perl -w -############################################################################### -# -# qrerun - PBS wrapper to cancel and resubmit a job -# -############################################################################### -# This file is part of SLURM, a resource management program. -# For details, see <http://slurm.schedmd.com/>. -# Please also read the included file: DISCLAIMER. -# -# SLURM is free software; you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free -# Software Foundation; either version 2 of the License, or (at your option) -# any later version. -# -# In addition, as a special exception, the copyright holders give permission -# to link the code of portions of this program with the OpenSSL library under -# certain conditions as described in each individual source file, and -# distribute linked combinations including the two. You must obey the GNU -# General Public License in all respects for all of the code used other than -# OpenSSL. If you modify file(s) with this exception, you may extend this -# exception to your version of the file(s), but you are not obligated to do -# so. If you do not wish to do so, delete this exception statement from your -# version. If you delete this exception statement from all source files in -# the program, then also delete it here. -# -# SLURM is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -# details. -# -# You should have received a copy of the GNU General Public License along -# with SLURM; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# -# Based off code with permission copyright 2006, 2007 Cluster Resources, Inc. -############################################################################### -use strict; -use FindBin; -use Getopt::Long 2.24 qw(:config no_ignore_case); -use lib "${FindBin::Bin}/../lib/perl"; -use autouse 'Pod::Usage' => qw(pod2usage); -use Slurm ':all'; -use Slurmdb ':all'; # needed for getting the correct cluster dims -use Switch; - -# Parse Command Line Arguments -my ( - $help, $man, - $err, $pid, $resp -); - -GetOptions( - 'help|?' => \$help, - '--man' => \$man, - ) or pod2usage(2); - -pod2usage(2) if $help; -# Handle man page flag -if ($man) -{ - if ($< == 0) # Cannot invoke perldoc as root - { - my $id = eval { getpwnam("nobody") }; - $id = eval { getpwnam("nouser") } unless defined $id; - $id = -2 unless defined $id; - $< = $id; - } - $> = $<; # Disengage setuid - $ENV{PATH} = "/bin:/usr/bin"; # Untaint PATH - delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; - if ($0 =~ /^([-\/\w\.]+)$/) { $0 = $1; } # Untaint $0 - else { die "Illegal characters were found in \$0 ($0)\n"; } - pod2usage(-exitstatus => 0, -verbose => 2); -} - - -# This makes the assumption JOBID will always be the last argument -my $job_id = $ARGV[$#ARGV]; - -if (@ARGV < 1) { - pod2usage(-message=>"Invalid Argument", -verbose=>1); - exit(1); -} - -if (Slurm->requeue($job_id)) { - $err = Slurm->get_errno(); - $resp = Slurm->strerror($err); - pod2usage(-message=>"Job id $job_id rerun error: $resp", -verbose=>0); - exit(1); -} -exit(0); - -__END__ - -=head1 NAME - -B<qrerun> - To rerun a job is to terminate the job and return the job to the queued state in the execution queue in which the job currently resides. -If a job is marked as not rerunable then the rerun request will fail for that job. - -See the option on the qsub and qalter commands. - -It is aimed to be feature-compatible with PBS' qsub. - -=head1 SYNOPSIS - -B<qrerun> [-? | --help] [--man] [--verbose] <job_id> - -=head1 DESCRIPTION - -The B<qrerun> command directs that the specified job is to be rerun if possible. - -=head1 OPTIONS - -=over 4 - -=item B<-? | --help> - -a brief help message - -=item B<--man> - -full documentation - -=back - -=head1 EXIT STATUS - -On success, B<qrerun> will exit with a value of zero. On failure, B<qrerun> will exit with a value greater than zero. - -=head1 SEE ALSO - -qalter(1) qsub(1) -=cut +#! /usr/bin/perl -w +############################################################################### +# +# qrerun - PBS wrapper to cancel and resubmit a job +# +############################################################################### +# This file is part of SLURM, a resource management program. +# For details, see <http://slurm.schedmd.com/>. +# Please also read the included file: DISCLAIMER. +# +# SLURM is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# In addition, as a special exception, the copyright holders give permission +# to link the code of portions of this program with the OpenSSL library under +# certain conditions as described in each individual source file, and +# distribute linked combinations including the two. You must obey the GNU +# General Public License in all respects for all of the code used other than +# OpenSSL. If you modify file(s) with this exception, you may extend this +# exception to your version of the file(s), but you are not obligated to do +# so. If you do not wish to do so, delete this exception statement from your +# version. If you delete this exception statement from all source files in +# the program, then also delete it here. +# +# SLURM is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along +# with SLURM; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Based off code with permission copyright 2006, 2007 Cluster Resources, Inc. +############################################################################### +use strict; +use FindBin; +use Getopt::Long 2.24 qw(:config no_ignore_case); +use lib "${FindBin::Bin}/../lib/perl"; +use autouse 'Pod::Usage' => qw(pod2usage); +use Slurm ':all'; +use Slurmdb ':all'; # needed for getting the correct cluster dims +use Switch; + +# Parse Command Line Arguments +my ( + $help, $man, + $err, $pid, $resp +); + +GetOptions( + 'help|?' => \$help, + '--man' => \$man, + ) or pod2usage(2); + +pod2usage(2) if $help; +# Handle man page flag +if ($man) +{ + if ($< == 0) # Cannot invoke perldoc as root + { + my $id = eval { getpwnam("nobody") }; + $id = eval { getpwnam("nouser") } unless defined $id; + $id = -2 unless defined $id; + $< = $id; + } + $> = $<; # Disengage setuid + $ENV{PATH} = "/bin:/usr/bin"; # Untaint PATH + delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; + if ($0 =~ /^([-\/\w\.]+)$/) { $0 = $1; } # Untaint $0 + else { die "Illegal characters were found in \$0 ($0)\n"; } + pod2usage(-exitstatus => 0, -verbose => 2); +} + + +# This makes the assumption JOBID will always be the last argument +my $job_id = $ARGV[$#ARGV]; + +if (@ARGV < 1) { + pod2usage(-message=>"Invalid Argument", -verbose=>1); + exit(1); +} + +if (Slurm->requeue($job_id)) { + $err = Slurm->get_errno(); + $resp = Slurm->strerror($err); + pod2usage(-message=>"Job id $job_id rerun error: $resp", -verbose=>0); + exit(1); +} +exit(0); + +__END__ + +=head1 NAME + +B<qrerun> - To rerun a job is to terminate the job and return the job to the queued state in the execution queue in which the job currently resides. +If a job is marked as not rerunable then the rerun request will fail for that job. + +See the option on the qsub and qalter commands. + +It is aimed to be feature-compatible with PBS' qsub. + +=head1 SYNOPSIS + +B<qrerun> [-? | --help] [--man] [--verbose] <job_id> + +=head1 DESCRIPTION + +The B<qrerun> command directs that the specified job is to be rerun if possible. + +=head1 OPTIONS + +=over 4 + +=item B<-? | --help> + +a brief help message + +=item B<--man> + +full documentation + +=back + +=head1 EXIT STATUS + +On success, B<qrerun> will exit with a value of zero. On failure, B<qrerun> will exit with a value greater than zero. + +=head1 SEE ALSO + +qalter(1) qsub(1) +=cut