
t0astbandit
Novice
Jan 23, 2009, 8:12 AM
Post #1 of 8
(633 views)
|
|
script for 5.8.6 not working in 5.8.8 or 5.10.0
|
Can't Post
|
|
I have a script on a slackware 9 box, using perl 5.8.6 (I know, these are oldballs, but i didn't set them up). The script works fine there, but there are 5 other servers using Debian Etch, with either 5.8.8 or 5.10.0 where it does not work. I've been racking my brain all week to figure out what was changed to make it stop working. I didn't write the script, set up the boxes or do the perl upgrade, so that's making it more difficult. Basically the script queries a database server, then checks to see if there were any changes and either dies or updates a file. I also tried to bundle the perl modules on the working server and import them to one of the others. I didn't have high hopes for it to work, and it didn't :( It's also not logging, but I'm not really concerned with that at the moment. I'm wondering if someone has a couple minutes to give it a look and see if they notice something I've missed. I've tried everything I can think of and am coming up with nothing. Any help would be GREATLY appreciated! Below is the script:
#!/usr/bin/perl # # use VI with ":set tabstop=3" to view/edit properly. # use strict; use DBI; use DBD::mysql; my $debug = 0; my $mysql_server = 'servername'; my $mysql_db = 'databasename'; my $mysql_user = 'uername'; my $mysql_pass = 'password'; my $timestamp_file = '/var/qmail/qpsmtpd/timestamp.update_recip_lists'; my $logfile = '/var/log/update_recip_lists.log'; open( STDOUT, ">$logfile" ); open( STDERR, ">>$logfile" ); &main(); close(STDOUT); close(STDERR); sub main() { my $lastrun = &get_lastrun(); my $thisrun; my $query = "select distinct domain, NOW()+0 from recip_lists where timestamp > $lastrun"; my $dbh = DBI->connect("DBI:mysql:$mysql_db:$mysql_server", $mysql_user, $mysql_pass); $dbh->do("use $mysql_db"); my $sth = $dbh->prepare($query) || die print("DBI could not prepare sth in sub main: " . $dbh->errstr()); $sth->execute() || die print("DBI could not execute sth in sub main: " . $dbh->errstr()); while (my @ary = $sth->fetchrow_array()) { $thisrun = $ary[1] if ($ary[1] > $thisrun); print("Updating recipient lists for: $ary[0]"); &update_lists($ary[0]); } $sth->finish(); $dbh->disconnect(); if ($thisrun) { system("echo -n $thisrun > $timestamp_file"); #system("/usr/local/bin/timuel_restart_everything"); } else { print("no updates since $lastrun, nothing to do here."); }; system("/usr/bin/touch $timestamp_file"); } sub get_lastrun() { my $l = shift(); open(STAMP, $timestamp_file); $l = <STAMP>; close(STAMP); chomp($l); if (!$l) { my $query = "select NOW()+0"; my $dbh = DBI->connect("DBI:mysql:$mysql_db:$mysql_server", $mysql_user, $mysql_pass); my $sth = $dbh->prepare($query) || die print("DBI could not prepare sth in sub get_lastrun: " . $dbh->errstr()); $sth->execute() || die print("DBI could not execute sth in sub get_lastrun: " . $dbh->errstr()); my @result = $sth->fetchrow_array; $sth->finish(); $dbh->disconnect(); $l = $result[0]; print("$timestamp_file did not exist, using new value $l"); system("echo -n $l > $timestamp_file"); } return($l); } sub update_lists() { my (%sql_hashref, %file_hash, $configfile, $tempfile); my $update_domain = lc($_[0]); my $validation_pref; my $dbh = DBI->connect("DBI:mysql:$mysql_db:$mysql_server", $mysql_user, $mysql_pass); $dbh->do("use $mysql_db"); my $query = "select recip_validation from prefs where user = \"$update_domain\""; my $sth = $dbh->prepare($query) || die print("DBI could not prepare sth in sub update_lists: " . $dbh->errstr()); $sth->execute() || die print("DBI could not execute sth in sub update_lists: " . $dbh->errstr()); while (my @ary = $sth->fetchrow_array()) { $validation_pref = $ary[0]; } print "$update_domain wishes to use $validation_pref recipient validation\n"; my $configfile = '/var/qmail/qpsmtpd/config/'.$update_domain.'/'.$validation_pref; $tempfile = '/var/qmail/qpsmtpd/config/'.$update_domain.'/'.$validation_pref.'.TEMP'; print "DOMAIN configfile is $configfile\n" if ($debug); if ($validation_pref eq "goodrcptto" || $validation_pref eq "badrcptto") { open(TEMPFILE, ">$tempfile"); $query = "select uname from recip_lists where domain = \"$update_domain\" and $validation_pref = 1"; $sth = $dbh->prepare($query) || die print("DBI could not prepare sth in sub update_lists: " . $dbh->errstr()); $sth->execute() || die print("DBI could not execute sth in sub update_lists: " . $dbh->errstr()); while (my @ary = $sth->fetchrow_array()) { #print("inserting $ary[0]".'@'."$update_domain into $configfile\n"); next if ($ary[0] eq "CCMDEFAULT"); die("refusing to create blank goodrcptto file") if ($validation_pref eq "goodrcptto" && !$ary[0]); $ary[0] = lc($ary[0]); print TEMPFILE $ary[0].'@'.$update_domain."\n"; }; }; my $existingupgoodrcptto= '/var/qmail/qpsmtpd/config/'.$update_domain.'/goodrcptto'; my $backupgoodrcptto = '/var/qmail/qpsmtpd/config/'.$update_domain.'/goodrcptto.BAK'; my $existingbadrcptto = '/var/qmail/qpsmtpd/config/'.$update_domain.'/badrcptto'; my $backupbadrcptto = '/var/qmail/qpsmtpd/config/'.$update_domain.'/badrcptto.BAK'; system("mv $existingupgoodrcptto $backupgoodrcptto") if (-f $existingupgoodrcptto); system("mv $existingbadrcptto $backupbadrcptto") if (-f $existingbadrcptto); system("mv $tempfile $configfile") if (-f $tempfile); }
(This post was edited by t0astbandit on Jan 23, 2009, 8:19 AM)
|