I have Red hat 7.1 . I have a script that scans the common drive and gathers file owner name , size, and last access date . and dumps into a DB. the second half if the script gets owners name and looks up in another table .. that I have been manually installing user name to email . I want the script if It cant find a email for the user , it will email to remind me to research the name and enter a email. The problem is quering the table and what is the result when It doesnt find an email for this users Here is the Code
################################################################# ##### Open userfile and put into an array ##### ################################################################# open(LOG,"</var/www/html/bad/users.txt"); @logmess = <LOG>; close(LOG); ###################################### ### get dink users email address ### ###################################### my $database = "shared"; my $data_source = "DBI:mysql:$database"; my $username = "root"; my $password = "elaine"; $dbh1 =DBI ->connect($data_source, $username, $password) or die "cant connect to $data_source : my $dbh-> errstr\n"; ## this is broke needs something that reads results NULL or none foreach $mess1(@logmess) { my $sth1 = $dbh1 -> prepare("select email from users where owner = '$mess1'"); $sth1 -> execute or die " unable to execute query "; my $array_ref = $sth1->fetchall_arrayref(); ## ^^^^^^^^^^^^^^^^^^^^^^^^ # add string to check if query came back negitive # # ( check other scripts ) # # print "Name : $mess1\n"; # # foreach $row(@$array_ref) { my ($email_u) = @$row; print "$mess1 and $email_u\n"; if ($email_u eq NULL){ print "the is Bad: $mess1\n"; open(LOG3,">>/var/www/html/bad/Badusers.txt"); print LOG3 "$mess1\n"; close(LOG3); } if($email_u ne ""){ ##### get files and email user open(MAIL, "|/usr/lib/sendmail -t")|| &ErrorMail; print MAIL "To:$email_u\nFrom:jim.flaherty\@somewhere.com\n"; print MAIL "Subject:Unused files on shared drive\n\n\n"; print MAIL "The following listed files are Files you own on the Shared drive\n"; print MAIL "( Drive s:) havent been accessed for 6 months. Please Click on \n"; print MAIL " the link below to review your files. "; print MAIL " Please delete any unnessary files : "; print MAIL " http://kins2158/bad/$mess1"; print MAIL "\n\n If you have any questions please call Jim Flaherty at 3420"; close(MAIL); } }