initstats.pl 2.13 KB
Newer Older
1
#!/usr/bin/perl -w
2 3
#
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
23
#
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
use English;

use lib "/usr/testbed/lib";
use libdb;
use libtestbed;

#
# Untaint the path
# 
$ENV{'PATH'} = '/bin:/usr/bin:/usr/sbin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

$query_result =
    DBQueryFatal("select pid,gid from groups");

while (($pid,$gid) = $query_result->fetchrow_array()) {
    if ($pid eq $gid) {
	print "insert into project_stats (pid) values ('$pid');\n";
    }
    print "insert into group_stats (pid,gid) values ('$pid', '$gid');\n";
}

$query_result =
47
    DBQueryFatal("select uid from users");
48

49 50
while (($uid) = $query_result->fetchrow_array()) {
    print "insert into user_stats (uid) values ('$uid');\n";
51 52 53
}

$query_result =
54
    DBQueryFatal("select eid,pid,expt_head_uid,gid,expt_created,batchmode,idx ".
55 56
		 "from experiments order by expt_swapped");

57
while (($eid,$pid,$creator,$gid,$created,$batchmode,$exptidx) =
58 59
       $query_result->fetchrow_array()) {

60 61 62 63 64 65 66 67 68
    print "insert into experiment_resources (idx, tstamp, exptidx) ".
	"values (0, '$created', $exptidx);\n";
    
    print "insert into experiment_stats ".
	"(eid, pid, creator, gid, created, batch, exptidx, rsrcidx) ".
        "select '$eid', '$pid', '$creator', '$gid', '$created', $batchmode,".
	"$exptidx,r.idx from experiments as e ".
	"left join experiment_resources as r on e.idx=r.exptidx ".
	"where pid='$pid' and eid='$eid';\n";
69
}