We help IT Professionals succeed at work.
Get Started

Can't locate DBI.pm in @INC

AlexAmbler
AlexAmbler asked
on
1,935 Views
Last Modified: 2012-05-09
Hi,

I am trying to use scheduled tasks (cron) in plesk to send a daily reminder to an email address for birthdays in my office,
The code is below, when it runs I get the following error message.

Can't locate DBI.pm in @INC (@INC contains: C:/Program Files/Parallels/Plesk/Additional/Perl/lib C:/Program Files/Parallels/Plesk/Additional/Perl/site/lib .) at C:\inetpub\vhosts\httpdocs\testserver\email2.pl line 4.
BEGIN failed--compilation aborted at C:\inetpub\vhosts\httpdocs\testserver\email2.pl line 4.

I have checked to see if DBI is installed using the command perl –MCPAN –e “installed DBI”

I get the response DBI is up to date (1.611)

Can you please help?

#!/usr/local/bin/perl  

use strict;
use DBI;
use CGI;
use MIME::Lite;

use POSIX qw( strftime );
my $mmddyyyy = strftime("%m/%d/%Y", localtime);
my $mm = strftime("%m", localtime);
my $dd = strftime("%d", localtime);
my $yy = strftime("%Y", localtime);

 # Enter Database info
 my $USERNAME = "888";
 my $PASSWORD = "888";
 my $DATABASE = "888";

my $dbh = DBI->connect("dbi:mysql:$DATABASE:localhost:3306", "$USERNAME", "$PASSWORD");

# if ID is an int, this should be "ID = 0" but if it is a char or varchar, it is correct
my $settings1 = $dbh->prepare("select * From settings WHERE ID = '0'");  
$settings1->execute();  

# since you are selecting * that must include ID, but you don't have ID in this list.
# Assuming it is the first field in the row, I've added it
while (my ($ID, $Path, $Ops_Email, $From_Email, $Subject, $Monthly_Email, $Email_Reminders) = $settings1->fetchrow_array()) {

	# move on if we aren't doing anything
	next unless $Email_Reminders == 1 or $Monthly_Email == 1;

	# Daily Reminders
	if ($Email_Reminders == 1) {

		# We'll add the start and end of the body only if there were any birthdays today
		my ($dailycount,$body);
		$sth->execute();
		while(my ($Name, $Address, $City, $State, $Postal, $Country, $B_Date) = $sth->fetchrow_array()) {  
			# Add one to the $dailycount
			$dailycount++;

			# Get just the year of $B_Date by getting rid of everything after the first dash
			(my $B_Year = $B_Date) =~ s/-.*//;
			my $age = $yy - $B_Year;

			$body .= "     $Name (Turns $age!)\n";

		}
		$sth->finish;
		$body .= "\n";

		# don't send any if there are none
		if ($dailycount > 0) {
			$body = <<EOL;
Hello!,

This Is Your Automated Birthday Reminder.

The following people have their birthday TODAY:

$body
This is an automated message, please do not respond.
EOL

			# You are sending one email per row in the table "settings" so it must be within that loop
			my $msg = MIME::Lite->new(
				From     =>$From_Email,
				To       =>$To_Email,
				Subject  =>$Subject,
				Data     =>$body
			);
			### Send in the "best" way (the default is to use "sendmail"):
			$msg->send;
		}
	}
	# end Daily Reminders 

	# Do monthly reminders if it is the first of the month
	if ($dd == 1) {
		################  
		# MONTHLYEMAIL #  
		################  

		# prepare the query  
		my $sthMonthly = $dbh->prepare("select * From teamdates WHERE `B_Date` LIKE '%-$mm-%'");  

		# execute the query  
		$sthMonthly->execute();  

		# We'll add the start and end of the body only if there were any birthdays today
		my ($monthcount,$body);
		while(my ($Name, $B_Date) = $sthMonthly->fetchrow_array()) {
			$monthcount++;

			# Get just the year of $B_Date by getting rid of everything after the first dash
			(my $B_Year = $B_Date) =~ s/-.*//;
			my $age = $yy - $B_Year;
			$body .= "     $Name (Turns $age2!) $B_Date\n";
		};  
		if ($monthcount) {

			## Mail Body  
			my $body = <<EOL;
Hello!,  

This Is Your Automated Reminder.  

The following people have their birthday this MONTH:\n\n";  

$body
This is an automated message, please do not respond.
EOL

			my $msg = MIME::Lite->new(
				From     =>$From_Email,
				To       =>$Ops_Email,
				Subject  =>$Subject,
				Data     =>$body
			);
			### Send in the "best" way (the default is to use "sendmail"):
			$msg->send;
		}
	}
}

Open in new window

Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE