 |
 |
Help with automating a mysql process...
|
 |
|
 |
|
Forum Regular
Join Date: Jul 2005
Status:
Offline
|
|
I'm currently running a survey for a website I help out on that needs to have its IP tables cleared every 6 hours. They're stored in a mySQL database. I know how to empty it manually in phpMyAdmin, but it's a pain in the ass making sure it gets done every 6 hours. Is there anything I can do on the server to automate the process? Maybe something like a cron job (which I know nothing about)?
Details: I'm using Dreamhost as a host. I know how to use command line stuff and have even done some basic programming, I just don't know where to start for this.
Thanks!
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: May 2004
Status:
Offline
|
|
Originally Posted by
I'm currently running a survey for a website I help out on that needs to have its IP tables cleared every 6 hours. They're stored in a mySQL database. I know how to empty it manually in phpMyAdmin, but it's a pain in the ass making sure it gets done every 6 hours. Is there anything I can do on the server to automate the process? Maybe something like a cron job (which I know nothing about)?
Details: I'm using Dreamhost as a host. I know how to use command line stuff and have even done some basic programming, I just don't know where to start for this.
Thanks!
Are you familiar with the [FONT="Courier New"]mysql[/FONT] command line utility?
|
╭1.5GHz G4 15" PB, 2.0GB RAM, 128MB VRAM, 100GB 7200rpm HD, AEBS, BT kbd
╰2.0GHz T2500 20" iMac, 1.5GB RAM, 128MB VRAM, 250GB 7200rpm HD
http://www.DogLikeNature.com/
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jul 2004
Status:
Offline
|
|
Well i only know how to do it through php but...
If your host allows cron jobs which most do with cpanel.
Go to Cron job. Choose Standard.
Use the new entry. and set it for every day and every 6 hours.
on the command to run do this
Code:
php -q /Pathtofile/EmtpyIpLog.php
the path to file would be from complete path php would have to go
ex. /home/username/crons/EmtpyIpLog.php
It is best to put this somewhere below the web root so nobody can execute it themselves.
In the php file have it connect to the mysql server. get the database. Empty the table
something like this. which is off the top of my head hope its right
Code:
<?
$connect = mysql_connect('localhost', 'Username', 'Password');
$dbname = 'Mydatabase';
$table = 'logs_ip';
$select = mysql_select_db($dbname, $link);
$result = mysql_query("TRUNCATE TABLE `".$table."`");
$numfields = mysql_num_fields($result);
echo $numfields . ' were removed from ' . $table . ' on the database '. $dbname;
mysql_close($connect);
?>
Make sure to have it off to email you when it does the cron job or you will get a email every 6 hours.
|
|
You shouldn't make fun of nerds... you'll be working for one some day.
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Jul 2005
Status:
Offline
|
|
Cool, I'll try that. Thanks for the help!
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Jul 2005
Status:
Offline
|
|
Hmm...I get these two errors when I try to run that php script:
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link
Warning: mysql_num_fields(): supplied argument is not a valid MySQL result
I tried running it myself before setting up a cron job, just to make sure it worked. Any ideas as to what's wrong?
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jul 2004
Status:
Offline
|
|
Oh.. typo
Code:
<?
<?
$connect = mysql_connect('localhost', 'Username', 'Password');
$dbname = 'Database';
$table = 'log_ip';
$select = mysql_select_db($dbname, $connect);
$result = mysql_query("TRUNCATE TABLE `".$table."`");
mysql_close($connect);
?
|
|
You shouldn't make fun of nerds... you'll be working for one some day.
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Jul 2005
Status:
Offline
|
|
Working great, thanks so much!
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|