Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Help with automating a mysql process...

Help with automating a mysql process...
Thread Tools
Forum Regular
Join Date: Jul 2005
Status: Offline
Reply With Quote
Mar 13, 2006, 10:20 PM
 
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
Reply With Quote
Mar 13, 2006, 10:36 PM
 
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
Reply With Quote
Mar 13, 2006, 10:37 PM
 
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.
     
 (op)
Forum Regular
Join Date: Jul 2005
Status: Offline
Reply With Quote
Mar 14, 2006, 09:26 AM
 
Cool, I'll try that. Thanks for the help!
     
 (op)
Forum Regular
Join Date: Jul 2005
Status: Offline
Reply With Quote
Mar 14, 2006, 09:47 AM
 
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
Reply With Quote
Mar 14, 2006, 11:29 AM
 
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.
     
 (op)
Forum Regular
Join Date: Jul 2005
Status: Offline
Reply With Quote
Mar 15, 2006, 01:03 AM
 
Working great, thanks so much!
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:32 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2