#!/usr/bin/perl # # js -- Retrieve a job script from the pbsacct DB. # Copyright 2009 University of Tennessee # # License: GNU GPL v2; see ../COPYING for details. # Revision info: # $HeadURL$ # $Revision$ # $Date$ use POSIX; use DBI; # # Main program begins here # # my system name in DB $system=`hostname`; # figure out pbs server name (we need it later) if ( ! defined($ENV{"PBS_HOME"}) ) { die "\$PBS_HOME undefined!"; } $pbsspooldir=$ENV{"PBS_HOME"}; open(SERVERNAME,"<$pbsspooldir/server_name"); $pbsserver=; close(SERVERNAME); chop($pbsserver); # hack for sloppy admins who don't put the full hostname # in $PBS_HOME/server_name # ***WARNING*** you may have to comment out the following code if # the servername doesn't resolve for whatever reason if ( $pbsserver =~ /:/ ) { ($host,$port) = split(/:/,$pbsserver); @server=gethostbyname($server); $pbsserver=$server[0].":".$port; } else { @server=gethostbyname($pbsserver); $pbsserver=$server[0]; $host=$server[0]; } $dbhost="localhost"; $dbuser="pbsacct"; $dbpasswd="pbsRroxor"; $dbname="pbsacct"; $dbtable="Jobs"; while ( $ARGV[0] =~ /^-.*/ ) { if ( $ARGV[0] eq "-d" ) { $dbname=$ARGV[1]; shift(@ARGV); } elsif ( $ARGV[0] eq "-h" ) { $system=$ARGV[1]; shift(@ARGV); } elsif ( $ARGV[0] eq "-p" ) { $dbpasswd=$ARGV[1]; shift(@ARGV); } elsif ( $ARGV[0] eq "-s" ) { $dbhost=$ARGV[1]; shift(@ARGV); } elsif ( $ARGV[0] eq "-t" ) { $dbtable=$ARGV[1]; shift(@ARGV); } elsif ( $ARGV[0] eq "-u" ) { $dbuser=$ARGV[1]; shift(@ARGV); } shift(@ARGV); } # connect to DB $dsn = "DBI:mysql:database=$dbname;host=$dbhost;"; $dbh = DBI->connect($dsn,$dbuser,$dbpasswd) || die "$0: unable to connect to DB!\n"; foreach $jobid ( @ARGV ) { # job script query $jobid =~ s/-[0-9]+.*//; $query = "SELECT script FROM Jobs WHERE system=\'".$system."\' AND jobid LIKE \'".$jobid.".\%\';"; #print STDERR $query."\n"; $sth = $dbh->prepare($query) or die "Could not prepare query: ".$dbh::errstr; $sth->execute() or die "Could not execute query: ".$dbh::errstr; while ( @data = $sth->fetchrow_array() ) { #print "script for jobid ".$jobid."\n---------------------------------\n"; print $data[0]; #print "\n---------------------------------\n"; } if ( $sth->rows==0 ) { print "No script found for jobid ".$jobid."\n"; } $sth->finish; } # disconnect from DB $dbh->disconnect();