Commit 9f194304 authored by mac's avatar mac
Browse files

No longer needed. Moved to attic.

parent 92da08e1
#!/usr/local/bin/perl -w
#!/usr/local/bin/perl -w
my $d=0; #debug
use Mysql;
my $dbh = Mysql->connect("localhost","tbdb","script","none");
my $sth ="";
my $cmd ="";
sub failed {
my ($cmd, $errstr) = @_;
print "Failed Command:\n$cmd\nError string is:$errstr\n";
}
#foreach my $node ( 21..40 ) {
# foreach my $ifc ( 0..3 ) {
# my $node_id = "tbpc".sprintf("%02d",$node);
# print "$node_id,eth$ifc: cable #? ";
# $_ = <STDIN>; chop;
# my $cable = $_;
# my $card = int (($node-1) / 6) + 3;
# print "",(int ((($node-1) % 6) / 3)),"\t",(($node+1) % 3),"\n";
# my $port = (int ((($node-1) % 6) / 3))+25+(($node-1) % 3)*8+$ifc*2 ;
# print "Inserting ($cable,$node_id,$ifc,$card,$port)...\n";
# $cmd = "replace into wires ".
# "(cable,node_id1,card1,card2,port2,port1,node_id2,type)".
# " values ($cable,'$node_id',$ifc,$card,$port,1,'cisco','Node');";
# $sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr) && last;
# }
#}
#foreach my $node ( 1..40 ) {
# my $node_id = "tbpc".sprintf("%02d",$node);
# print "$node_id,eth4: cable #? ";
# $_ = <STDIN>; chop;
# my $cable = $_;
# print "$node_id,eth4: card #? ";
# $_ = <STDIN>; chop;
# my $card = $_;
# print "$node_id,eth4: port #? ";
# $_ = <STDIN>; chop;
# my $port = $_;
# print "Inserting ($cable,$node_id,4,$card,$port)...\n";
# $cmd = "replace into wires ".
# "(cable,node_id1,card1,card2,port2,port1,node_id2,type)".
# " values ($cable,'$node_id',4,$card,$port,1,'cisco2','Control');";
# $sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr) && last;
#}
foreach my $shelf ( 1..20 ) {
foreach my $shark ( 1..8) {
my $shelf_id = "tbsh".sprintf("%02d",$shelf);
print "Changing $shelf_id-$shark to $shelf_id:$shark...\n";
$cmd = "update interfaces set node_id='$shelf_id',card='$shark' ".
"where node_id='$shelf_id-$shark';";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr) && last;
}
}
#!/usr/local/bin/perl -w
use DBI;
$driver = "mysql";
$dbh = DBI->connect("DBI:$driver:database=tbdb;host=localhost")
|| die "Could not connect.\n";
if ($#ARGV >= 0) {
foreach $id (@ARGV) {
$sth = $dbh->prepare("SELECT gid FROM grp_memb WHERE uid = \"$id\"");
$rr = $sth->execute;
if ($rr == 0) { #if $id is not a user ID, then see if it is a group ID.
$sth2 = $dbh->prepare("SELECT uid FROM grp_memb WHERE gid = \"$id\"");
$rr2 = $sth2->execute;
if ($rr2 == 0) {
print "The ID $id was not found in database.\n";
} else {
printer("Group ID $id:", $sth2);
}
} else {
printer("User ID $id:", $sth);
}
}
} else { #if there are no command line arguments print the entire table.
$sth = $dbh->prepare("SELECT * FROM grp_memb");
$sth->execute;
while (@row = $sth->fetchrow_array) {
foreach (@row) {
print "$_ ";
} print "\n";
}
}
sub printer { #a subroutine to return the information in Mysql tables.
print $_[0];
while (@row = $_[1]->fetchrow_array) {
foreach (@row) {
print " $_";
}
} print ".\n";
}
#!/usr/local/bin/perl -w
BEGIN {
use lib '/usr/testbed/lib/perl';
use Time::CTime;
use Time::ParseDate;
use DBI;
}
my %types = ("powercycle"=>1,"error"=>1,"note"=>1,"critical"=>1);
if ($#ARGV<0) {
die(" Usage: tblog -i|-s [-n <node_id>] [-u <uid>] [-t <type>] ".
"-m 'message text'\n\t[-b <time>] [-a <time>] [-e <exact>] [-c <complex>]\n".
" -i Insert entry\n -s Search log\n -n Node ID\n -u User ID\n".
" -t Entry type (".join(", ",sort keys %types).")\n".
" -m Message\n -b Before this time\n -a After this time\n".
" -e Exact match for message\n -c Complex query use AND &&, OR ||, NOT ! and node, uid, time, type, or message='somestring'.\n");
}
my $i=0;
my $s=0;
my $node ="";
my $uid ="";
my $type ="";
my $msg ="";
my $before="";
my $after ="";
my $exact = 0;
my $cmplx ="";
while (@ARGV != 0) {
$_ = shift(@ARGV);
# print ">Item=$_*\n";
# print " i=$i s=$s n=$node u=$uid t=$type m=$msg b=$before a=$after\n";
if (/^-i(.*)/) {$i = 1;}
elsif (/^-s(.*)/) {$s = 1;}
elsif (/^-n(.*)/) { $node = ($1 ? $1 : shift(@ARGV));}
elsif (/^-u(.*)/) { $uid = ($1 ? $1 : shift(@ARGV));}
elsif (/^-t(.*)/) { $type = ($1 ? $1 : shift(@ARGV));}
elsif (/^-m(.*)/) { $msg = ($1 ? $1 : shift(@ARGV));}
elsif (/^-b(.*)/) {$before= ($1 ? $1 : shift(@ARGV));}
elsif (/^-a(.*)/) { $after= ($1 ? $1 : shift(@ARGV));}
elsif (/^-e(.*)/) { $exact= 1;}
elsif (/^-c(.*)/) { $cmplx= ($1 ? $1 : shift(@ARGV));}
elsif (/^-h(.*)/) { exec "$0";}
else {die("Unknown Option: $_\n");}
}
#print "Got Args:\n";
#print "i=$i s=$s n=$node u=$uid t='$type' m='$msg' b='$before' a='$after'\n";
if ( $i==$s ) {
die("You must select exactly one of '-i' or '-s'.\n");
}
if ( $type ne "" && !defined $types{$type} ) {
die("Invalid type '$type'. Must be in (".join(" ",sort keys %types).").\n");
}
if ( $i && (!defined $msg || !$msg) ) {
die("You must specify a message string.\n");
}
# Escape any special characters in the message
if (defined $msg) {
$msg =~ s/([^\\])([\'\"\\])/$1\\$2/;
}
#print "Message updated to '$msg'\n";
my $dbh = DBI->connect ("DBI:mysql:database=tbdb;host=localhost")
|| die "Could not connect to TBDB.\n";
# SEARCH THE LOG
if ($s) { # constructs the where clause of the mysql command
if ($cmplx ne "") {
$cmplx =~ s/^node=/node_id=/g;
$cmplx =~ s/^time=/entry_time=/g;
$cmplx =~ s/^type/log_type/g;
$sth = $dbh->prepare("SELECT * FROM log WHERE $cmplx");
} else {
my $param = "WHERE";
if ($node ne "") {
$param .= " AND" if ($param ne "WHERE");
$param .= " node_id='$node'";
}
if ($uid ne "") {
$param .= " AND" if ($param ne "WHERE");
$param .= " uid='$uid'";
}
if ($msg ne "") {
$param .= " AND" if ($param ne "WHERE");
if ($exact) {
$param .= " message='$msg'";
} else {
$param .= " message LIKE '%$msg%'";
}
}
if ($before ne "") {
my $relbef = parsedate($before);
$param .= " AND" if ($param ne "WHERE");
$param .= " entry_time<=FROM_UNIXTIME($relbef)";
}
if ($after ne "") {
my $relaft = parsedate($after);
$param .= " AND" if ($param ne "WHERE");
$param .= " entry_time>=FROM_UNIXTIME($relaft)";
}
$sth = $dbh->prepare("SELECT * FROM log $param");
}
$sth->execute || die "Could not query database: $sth->errstr.\n";
while(@log = $sth->fetchrow_array) {
($entry_id, $node_id, $uid, $entry_time, $log_type, $message) = @log;
my $sth2 = $dbh->prepare("SELECT UNIX_TIMESTAMP($entry_time)");
$sth2->execute || die "Failure to execute time manipulations.\n";
my ($reltime) = ($sth2->fetchrow_array);
my $fancytime = strftime("%c", $reltime);
print "$entry_id:$node_id:$uid:$fancytime:$log_type:$message.\n";
}
}
# INSERT AN ENTRY
if ($i) {
if (!defined $type || $type eq "") { $type = "note"; }
$uid = (getpwuid($<))[0];
my $query = "INSERT INTO log VALUES ('', '$node', '$uid', now(), '$type', '$msg')";
print "$query\n";
my $sth = $dbh->prepare($query);
$sth->execute
|| die "Failed to insert the entry into the log: $sth->errstr.\n";
}
$dbh->disconnect;
#!/usr/local/bin/perl -w
my $user = (getpwuid($<))[0]
|| die "Cannot figure out who you are!\n";
print "You are: ",join(":",getpwuid($<)),"\n";
# When run through a root setuid program, $< is the user, $> is the
# acquired personality
print "I am $user, $<, $>\n";
#!/usr/local/bin/perl -w
use DBI;
$dbh = DBI->connect ("DBI:mysql:database=tbdb;host=localhost")
|| die "Could not connect.\n";
if ($#ARGV == 2) {
($uid, $udt, $new) = @ARGV;
$sth = $dbh->prepare("UPDATE users SET $udt = \"$new\" WHERE uid = \"$uid\"");
$rr = $sth->execute;
$rr == 1 || die "Command not executed properly.\n";
print "$udt changed to $new for user $uid.\n";
} else {
print "usrmod expects first a user ID then the column to be updated and finally the new value.\n";
}
#!/usr/local/bin/perl -w
use DBI;
$driver = "mysql";
$dbh = DBI->connect("DBI:$driver:database=tbdb;host=localhost")
|| die "Could not connect.\n";
#A program to delete or add users to the tesbed database.
#"usrud -d UID" deletes that user from users, grp_memb and proj_memb.
#"usrud -a UID ..." adds a user to users along with information supplied on the command line
if ($#ARGV >= 1) {
($oper, @usrs) = @ARGV;
if ($oper eq '-d') {
foreach $n (@usrs) {
chomp($n);
$sth = $dbh->prepare("DELETE FROM users WHERE uid = \"$n\"");
$sth2 = $dbh->prepare("DELETE FROM grp_memb WHERE uid = \"$n\"");
$sth3 = $dbh->prepare("DELETE FROM proj_memb WHERE uid = \"$n\"");
$rr = $sth->execute;
$rr == 0 && die "User $n not found.\n";
$sth2->execute;
$sth3->execute;
print "User $n removed.\n";
}
} elsif ($oper eq '-a') {
chomp(@usrs);
$#usrs = 6;
$sth = $dbh->prepare("INSERT INTO users VALUES ('$usrs[0]', now(), '$usrs[1]', '$usrs[2]', '$usrs[3]', '$usrs[4]', '$usrs[5]', '$usrs[6]')");
$ra = $sth->execute;
$ra == 0 || print "User added.\n";
} else {
print "Incorrect command: \"-d\" or \"-a\" expected.\n";
}
} else {
print "Type the command \"-r\" and a username to remove an user from the database or \"-a\" and a user ID to add a new user to the database.\n";
}
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