#!/usr/bin/perl use Date::Manip; use DBI; use strict; my $mailprog = '/usr/lib/sendmail'; my $tomorrow=&DateCalc("today","+1day"); my $year = substr $tomorrow, 0, 4; my $month = substr $tomorrow, 4, 2; my $day = substr $tomorrow, 6, 2; my $tomorrow = $year."-".$month."-".$day; my ($dsn) = "DBI:mysql:andrewkmitchell_com:localhost"; # data source name my ($user_name) = "akm2"; # user name my ($password) = "merlin2562"; # password my ($dbh, $sth); # database and statement handles my (@ary); # array for rows returned by query # connect to database $dbh = DBI->connect ($dsn, $user_name, $password, { RaiseError => 1 }); # issue query my $query = qq{ SELECT id, name, event_date, start_time, end_time, description FROM ltw_events WHERE event_date="$tomorrow" }; $sth = $dbh->prepare ( $query ); $sth->execute (); open(MAIL,"|$mailprog -t"); print MAIL "To: akm2\@merlin-internet-services.net\n"; print MAIL "From: root\@merlin-Internet-Services.net (Re-minder)\n"; print MAIL "Subject: Reminder for Tomorrow ($tomorrow)\n"; print MAIL "X-Priority: 1 (Highest)\n\n"; print MAIL "This in an automatic message generated by Re-Mind. The purpose of this message is to remind you of event(s) you have scheduled for tomorrow ($tomorrow).\n\nEvents are listed below:\n\n"; while (@ary = $sth->fetchrow_array ()) { print MAIL join ("\t", @ary), "\n"; } print MAIL "\nEND OF SCHEDULED EVENTS!\n"; close(MAIL); $sth->finish (); $dbh->disconnect (); exit (0);