#!/usr/bin/perl -wT # # EMULAB-COPYRIGHT # Copyright (c) 2000-2002, 2004 University of Utah and the Flux Group. # All rights reserved. # use English; # Save the tiplogs from an experiment sub usage { print "Usage: $0 pid eid\n"; exit(-1); } # # Configure variables # my $TB = "@prefix@"; my $CONTROL = "@USERNODE@"; my $sshtb = "$TB/bin/sshtb"; # # Testbed Support libraries # use lib "@prefix@/lib"; use libdb; use libtestbed; # Locals my $SAVEUID = $UID; my $dbuid; # # Turn off line buffering on output # $| = 1; # # We don't want to run this script unless its the real version. # if ($EUID != 0) { die("*** $0:\n". " Must be root! Maybe its a development version?\n"); } # # Please run as yourself # if ($UID == 0) { die("*** $0:\n". " Please do not run this script as root!\n"); } # # Untaint the path # $ENV{'PATH'} = "/bin:/sbin:/usr/bin:/usr/sbin"; delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; if (@ARGV != 2) { usage(); } my ($pid,$eid) = @ARGV; # # Untaint args. # if ($pid =~ /^([-\w]+)$/) { $pid = $1; } else { die("*** Bad data in pid: $pid.\n"); } if ($eid =~ /^([-\w]+)$/) { $eid = $1; } else { die("*** Bad data in eid: $eid.\n"); } # Must exist in the DB. if (! UNIX2DBUID($UID, \$dbuid)) { die("*** $0:\n". " You do not exist in the Emulab Database!\n"); } # # Verify permission to muck with this experiment. This is to head off # permission problems early; the nodes are indvidually checked later # in the library. # if (!TBAdmin($UID) && !TBExptAccessCheck($UID, $pid, $eid, TB_EXPT_MODIFY)) { die("*** $0:\n". " You do not have permission to save log files in $pid/$eid!\n"); } # # Find the names of all physical nodes with tip lines. # my $query_result = DBQueryFatal("select r.node_id,r.vname,t.server from reserved as r ". "left join nodes as n on n.node_id=r.node_id ". "left join node_types as nt on nt.type=n.type ". "left join tiplines as t on t.node_id=r.node_id ". "where r.pid='$pid' and r.eid='$eid' and ". " nt.isvirtnode=0 and nt.isremotenode=0 and ". " t.server is not null"); if ($query_result->numrows == 0) { print "No console lines found for experiment $eid in project $pid!\n"; exit(0); } my $savedir = PROJROOT() . "/$pid/tiplogs/$eid"; my $cmdargs = "$TB/sbin/savelogs.proxy -u $dbuid -s $savedir "; while (my ($nodeid, $vname) = $query_result->fetchrow_array()) { $cmdargs .= " $nodeid $vname"; } # # Now we call over to the ops node to deal with the rest of this. # $EUID = $UID = 0; system("$sshtb -host $CONTROL $cmdargs"); $EUID = $UID = $SAVEUID; # # Nothing else to do ... output from proxy went to stdout/stderr. # exit($? >> 8);