template_record 1.79 KB
Newer Older
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
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2006 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use Getopt::Std;

#
# Do some analysis.
#
sub usage()
{
    print STDOUT "Usage: template_analyze <script> [args ...]\n";
    exit(-1);
}
my $optlist = "";

#
# Turn off line buffering on output
#
$| = 1;

# Drag in path stuff so we can find emulab stuff.
BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; }

#
# Load the OS independent support library. It will load the OS dependent
# library and initialize itself. 
# 
use libsetup;

#
# Need the pid/eid. 
# 
my ($pid, $eid, $vname) = check_nickname();

#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
    usage();
}
if (@ARGV < 1) {
    usage();
}
my $scriptname = shift(@ARGV);

#
# Grab the user environment variables.
#
open(USRENV, "/var/emulab/boot/tmcc/userenv")
    or die("Could not open user environment file!\n");

while (<USRENV>) {
    if ($_ =~ /^(.*)=(.*)$/) {
	$ENV{$1} = $2;
    }
}

#
# Run the analysis.
# If it completes okay then schedule an event for the current time.
#
my $now = time();
my $childpid = fork();
if (! $childpid) {
    #
    # Child runs command
    #
    exec $scriptname, @ARGV;
    die("Could not exec $scriptname\n");
}

#
# Wait until child exits or until user gets bored and types ^C.
#
waitpid($childpid, 0);
if ($?) {
    exit(-1);
}

#
# Okay, ssh over to ops to run the xmlrpc client. SHould be installed locally.
#
system("ssh -q -o BatchMode=yes -o StrictHostKeyChecking=no ops ".
       "  /usr/testbed/bin/sslxmlrpc_client.py -m template addprogevent ".
       "  proj=$pid exp=$eid vnode=$vname when=$now ".
       "  cmd=\"'$scriptname @ARGV'\"");
    
exit 0;