You are invited to Log in or Register a free Frihost Account!

Cron job

I need to create a cron-job that would loop through a MySQL table, compare today's date with a date listed in that table, then copy the listing with a difference between dates of 3 weeks or less to another table. I have no CGI/Perl experience, though, and I really don't want to get into ANOTHER language when I'm working on HTML, C++, PHP, and CSS at the same time. Can anyone help me with this? (Oh, and I'll be needing two other cron-jobs after this one. Laughing)
Stubru Freak
Just use php + sql
Stubru Freak wrote:
Just use php + sql

...and set up a cron job to run it.
So a cron job can run a PHP page too? I didn't know that. *blinks*

So (taking into account I need this cronjob for a website not utilizing DirectAdmon), all I'd need to do is add the .php file I want to use as a job to the crontab file? Or, actually considering that the crontab already lists folders for daily, weekly, and monthly stuff, I'd just add the file into one of those and be done with it?
No, you can't simply run a .php file. You need to parse it, of course. In Windows, you may use the php executable, but in Unix environment (where php is only a module) you may have to use a browser to parse it. Or, for better performance, use mysqladmin. You should have it installed.
Solugon, I don't have "mysqladmin". I have phpMyAdmin, but no mysqladmin. *scratches head in confusion*

Is there any way to parse a PHP file at a certain time without me having to do anything? And if it has to be done with this "mysqladmin" thing, where would I get it?
I think it is installed with MySQL. At least this was the case on my system (Debian). Do you get an error message if you type mysqladmin in a console window?
...Moment of stupidity on my part. I forgot I was doing this cron job without the use of the Direct Admin thing on my Frihost account, so I looked there instead. O_o

I'll go see if I have that in a while.
OK, I have mysqladmin. What can I do with it that'll help with my cron job problem?
I came home and started experimenting for you. I found out that you don't even need mysqladmin. Simply use mysql for your cron job. Like this:
00,30 * * * * mysql -e "SELECT * INTO newtable FROM oldtable WHERE DATE_SUB(CURDATE(), INTERVAL 21 DAY) <= date" -pYourPassword database_name

I can't guarantee that the above query will work. You may find more info at the MySQL Reference Manual.
I hope it finally helped. Good luck!
Oh, that's an interesting mySQL query. I'm a beginner at MySQL, so it's not surprising that I didn't know about a query like that, but what I find interesting is that (1) you can use a mySQL query like that in a cronjob, and (2) that I could compact what I thought would take up a bit more than 1 line of code can fit so compactly into a single MySQL query.

I'll try it and put it to use, thanks! And I'll look for some help documents on mysqladmin too. Thanks a lot. Very Happy
I read through the documentation here, but I don't see anything that could possibly help me with running a mysql query automatically periodically... I guess I'll just have to learn some Perl. From what I've seen, it's not too different from what I've learned so far...
What is the problem with the resolution I suggested? As you see, you can run a query using the mysql command. You can put this query in your crontab file. mysqladmin isn't needed at all - that was my fault.
Of course, learning Perl won't hurt... Very Happy
Actually, I tried that. I think it's likely an error on my end, because it didn't send me any errors, but when it runs, it doesn't do what it's supposed to (and that's move any entries with "date" older than a day to another table)...

I think Perl will just be more the way I like it, actually.
Related topics
cron jobs
Questions about cron jobs and permissions
Cron Job to Backup MySQL Database
cron job
How to run a cron job on a server
Database/PHP/Cron Jobs [Resolved]
what can a cron job do for you?
Cron job and browser output question
Cron job
ΏCron Job en Frihost?
How to get a php script working under a cron job?
Run a php Script with a Cron Job
Possible cron job usage?
Cron Job usage on FriHost
Reply to topic    Frihost Forum Index -> Scripting -> Others

© 2005-2011 Frihost, forums powered by phpBB.