#!/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`; # DB defaults $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();