savelogs.in 2.67 KB
Newer Older
1
#!/usr/bin/perl -wT
Leigh Stoller's avatar
Leigh Stoller committed
2 3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2002, 2004 University of Utah and the Flux Group.
Leigh Stoller's avatar
Leigh Stoller committed
5 6
# All rights reserved.
#
Leigh Stoller's avatar
Leigh Stoller committed
7
use English;
8 9 10 11 12 13 14 15 16 17 18 19

# Save the tiplogs from an experiment

sub usage {
	print "Usage: $0 pid eid\n";
	exit(-1);
}

#
# Configure variables
#
my $TB          = "@prefix@";
20 21
my $CONTROL	= "@USERNODE@";
my $sshtb	= "$TB/bin/sshtb";
22 23 24 25 26 27 28 29

#
# Testbed Support libraries
#
use lib "@prefix@/lib";
use libdb;
use libtestbed;

30 31 32 33
# Locals
my $SAVEUID = $UID;
my $dbuid;

34 35 36 37 38
#
# Turn off line buffering on output
#
$| = 1;

39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#
# 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");
}

55 56 57 58 59 60
#
# Untaint the path
# 
$ENV{'PATH'} = "/bin:/sbin:/usr/bin:/usr/sbin";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

61
if (@ARGV != 2) {
62
    usage();
63 64 65 66
}

my ($pid,$eid) = @ARGV;

67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
#
# 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");
}

83 84 85 86
# Must exist in the DB.
if (! UNIX2DBUID($UID, \$dbuid)) {
    die("*** $0:\n".
	"    You do not exist in the Emulab Database!\n");
87 88
}

89 90 91 92 93 94 95 96 97
#
# 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");
98 99
}

100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
#
# 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);
}
116

117 118
my $savedir = PROJROOT() . "/$pid/tiplogs/$eid";
my $cmdargs = "$TB/sbin/savelogs.proxy -u $dbuid -s $savedir ";
119

120 121
while (my ($nodeid, $vname) = $query_result->fetchrow_array()) {
    $cmdargs .= " $nodeid $vname";
122 123
}

124 125 126 127 128 129
#
# 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;
130

131 132 133 134
#
# Nothing else to do ... output from proxy went to stdout/stderr.
# 
exit($? >> 8);
135