This is a cut and paste from a working script so hopefully it will still work for you. Not saying that it is brilliant code but it is from the simplest perl crontab I have.
#!/usr/bin/perl -w
use CGI qw(param);
use DBI;
$db="xxxxxxxxxt";
# Connect to the database region.
&dbstartup;
$query = "SELECT a.seq, a.peer, a.username, a.domain, a.page, a.pagename, a.lastread, a.lasttstamp, b.email, b.emailfrom FROM web a, user b where a.username = b.username and a.active = 'Y'";
&dbquerystart;
while ($row = $sth->fetchrow_hashref)
{
$wuser = $row->{'username'};
$wemail = $row->{'email'};
$wemailfrom = $row->{'emailfrom'};
$wpeer = $row->{'peer'};
$wdomain = $row->{'domain'};
$wpage = $row->{'page'};
$wpagename = $row->{'pagename'};
$wlastread = $row->{'lastread'};
$wseq = $row->{'seq'};
&process_row;
}
&dbqueryend;
#Closedown the database connection
&dbshutdown;
exit(0);
sub process_row {
.... drop the table stuff would go in here ie
$query2 = "DROP ............";
&dbquerystart2;
&dbqueryend2;
return 1;
}
#########################################################################
sub dbstartup {
# Connect to the database region.
$sock = "/tmp/mysql.xxxxxxx";
$user = $db;
$pass = $db;
$dsn = "DBI:mysql:$db;mysql_socket=$sock";
$dbh = DBI->connect($dsn,$user,$pass);
return 1;
}
sub dbshutdown {
$dbh->disconnect();
return 1;
}
# Startup and SQL statement (stored in $query) and get the rowcount
sub dbquerystart {
$sth = $dbh->prepare($query);
$sth->execute;
$rcount = $sth->rows;
return 1;
}
# close off the SQL statement last executed
sub dbqueryend {
$sth->finish();
return 1;
}
# Startup and SQL statement (stored in $query) and get the rowcount
sub dbquerystart2 {
$sth2 = $dbh->prepare($query2);
$sth2->execute;
$rcount2 = $sth2->rows;
return 1;
}
# close off the SQL statement last executed
sub dbqueryend2 {
$sth2->finish();
return 1;
}
To setup the crontab you want to be logged in as the user you want to use (for simiplicity) and have a file containing the details of what you want to run and when (see man crontan)
ie.
0,15,30,45 1-23/1 * /home/xxxx/mindit.pl >>/home/xxxx/weblog 2>>/home/xxxx/weblog2
this would run a script every 15 minutes every day while the hour is between 1-23 and sticks the output in the mentioned files.
Save the file for example as cronfile and then enter the command crontab cronfile when logged in as the user.