Commit febe5dab authored by Robert Ricci's avatar Robert Ricci

Some of the scripts I've been working on to process and normalize top

and ptop files. They are intended for rolling distributions of historical
topology information.

check-top is essentially a full perl parser for top and ptop files, and
should make it relatively easy to convert to other file formats.
parent 42b96d65
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2007 University of Utah and the Flux Group.
# All rights reserved.
#
#
# Script for anonymizing directories from /usr/testbed/expinfo on boss. Parses
# the names of top-level directories, remvoving the <eid> and <pid> portions,
# leaving only the <id> portion of the directory name.
#
# If it finds any potential errors, does nothing.
#
use strict;
if (@ARGV != 1) {
die "Usage: $0 <directory>\n";
}
my ($dirname) = @ARGV;
my @names;
if ($dirname eq "-") {
@names = <STDIN>;
} else {
@names = `ls -1 $dirname`;
}
chomp @names;
my $errors = 0;
# Check for duplicate IDs
my %ids;
# Build up a list of commands - only execute them if there are no errors
my @commands;
foreach my $name (@names) {
# Find the ID # in the filename
my $id;
if ($name =~ /\.(\d{3,})$/) {
$id = $1;
} elsif ($name =~ /-(\d+-\d+\.\d+\.\d+)$/) {
$id = $1;
} else {
warn "***: Unable to find ID number in '$name'\n";
$errors++;
next;
}
if ($ids{$id}) {
warn "***: Duplicate ID number $id ('$name') ";
$errors++;
next;
} else {
$ids{$id} = 1;
}
# if (-d $name) {
# # Recurse into the directory
# system "cd $name && $0 .\n";
# }
push @commands, "mv $name $id";
}
if ($errors) {
exit(1);
} else {
foreach my $cmd (@commands) {
if (system $cmd) {
print "*** Error running '$cmd'!\n";
}
}
exit(0);
}
This diff is collapsed.
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2007 University of Utah and the Flux Group.
# All rights reserved.
#
#
# Script for renaming files within expinfo diretoriesl. To be run after
# anonymize-expinfo, and does a similar operation to the files within the
# directory.
#
# Intentionally supports only top and ptop files for now, but can be extended
# to handle others
#
# If it finds any potential errors, does nothing.
#
use strict;
my @dirs = `ls -1 .`;
chomp @dirs;
my $errors = 0;
my @commands;
foreach my $dir (@dirs) {
next unless -d $dir;
my @files = `ls -1 $dir`;
chomp @files;
my $newname;
my %newnames;
foreach my $file (@files) {
if ($file =~ /^([\w-]+)-(\d+\.p?top)$/) {
#print "top/ptopfile with ID: $file\n";
$newname = "$dir-$2";
} elsif ($file =~ /^([\w-]+)-(\d+-empty\.ptop)/) {
#print "Empty ptop file: $file\n";
$newname = "$dir-$2";
} elsif ($file =~ /^([\w-]+)-(\d+-coarsened\.top)/) {
#print "Empty ptop file: $file\n";
$newname = "$dir-$2";
} elsif ($file =~ /^([\w-]+)(\.p?top)$/) {
#print "Plain top/ptopfile: $file\n";
$newname = "${dir}$2";
} else {
warn "***: Filneame I don't recognize: $file\n";
$errors++;
}
if ($newnames{$newname}) {
warn "***: I want to rename two files $dir/${newname}: " .
"$newnames{$newname} and $file\n";
$errors++;
} else {
$newnames{$newname} = $file;
push @commands, "mv $dir/$file $dir/$newname\n";
}
}
}
if ($errors) {
exit(1);
} else {
foreach my $cmd (@commands) {
if (system $cmd) {
print "*** Error running '$cmd'!\n";
}
}
exit(0);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment