#!/opt/SPYNuptm/bin/perl -I/opt/SPYNuptm/lib/perl use File::Spec::Functions; use Cwd; use uptime; $tmp = catfile( ( $UPT_TEMPDIR ), "$$.inp" ); $dbcmd = upt_catfile( ( $UPT_BINDIR ), "dbcmd" ); $devnull = File::Spec->devnull; $outfile = catfile( ( $UPT_TEMPDIR ), "dbcheck$$.out" ); $UPT_DATADIR =~ s/\"//g; foreach ( @ARGV ) { if ( /--repair/ ) { $repair = 1; last; } } opendir( DH, $UPT_DATADIR ); @dirent = grep { /\.MYI$/ } readdir( DH ); closedir( DH ); @direntries = sort {uc($a) cmp uc($b)} @dirent; foreach $tablename ( @direntries ) { chomp; $tablename =~ s/^(.*)\.MYI$/$1/; print "Checking table $tablename\n"; $commands = "check table $tablename;"; open( FH, ">${tmp}" ); print FH $commands; close( FH ); $cmd = "$dbcmd <$tmp 2>$devnull"; `$cmd >> $outfile`; } if ( $repair ){ # repair tables print "Checking for corrupt tables...\n"; open( FH, "<${outfile}" ); my @list = ; close FH; while( @list ) { chomp; $line = shift(@list); if ( $line =~ m/Corrupt/ ){ @lines = split( /\s/, $line ); $tablename = $lines[0]; print "Repairing table $tablename\n"; $commands = "repair table $tablename;"; open( FH, ">${tmp}" ); print FH $commands; close( FH ); $cmd = "$dbcmd <$tmp 2>$devnull"; `$cmd >> $outfile`; } } } unlink( $tmp ); @localtime = localtime( time ); $datestr = sprintf( "%04d%02d%02d", $localtime[5] + 1900, $localtime[4] + 1, $localtime[3] ); if( $UPT_ISWINDOWS ) { $utf = upt_catfile( ( $UPT_BASEDIR, "temp" ), "uptime_dbcheck_$datestr" ); `move $outfile $utf`; print "The ouptut file is $utf\n"; } else { $utf = catfile( ( $UPT_TEMPDIR ), "uptime_dbcheck_$datestr" ); `mv $outfile $utf`; print "The output file is $utf\n"; } exit 0;