|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
using Perl to update MySQL automatically?
Hi there!
I'm writing a Perl program that looks for certain information on our server and then writes a set of insert/update instructions in a text file in order to update the MySQL database with the new information. The only problem is that I would like this entire process to run automatically. Therefore, I have a two part problem. First, I can't quite figure out how to get the Perl program to run automatically...i.e. once every day, and secondly I'm not sure how to get the Perl to automatically update the MySQL or have the MySQL automatically run the set of update instructions. Therefore, I was wondering if anyone knows how? Is it supposed to be done from the Perl side or the MySQL side? I'm pretty much a newbie to Perl so any help would be appreciated. thanks (a lot) in advance, xijia ![]() P.S. sorry this thread involves so many topics! ![]() |
|
#2
|
|||
|
|||
|
I know how to do this, email me: aa@tut.by
|
|
#3
|
||||
|
||||
|
More to the point, if you're on a unix host, you want to find out how to add a job to "crontab," which allows you to run scripts / programs on pretty much any schedule you want, daily, hourly, every sunday, etc.
On a windows host, I couldn't tell you. I don't host websites on windows. |
|
#4
|
|||
|
|||
|
To run a perl program automatically on the remote machine you need
- a telnet access to that machine. - to insert some lines into your script: example... ------- #!/usr/bin/perl $pr=fork || die; exit if $pr; # these 2 lines allow program running when you close your telnet connection while (1){ # here's your never-ending cycle that keeps program running if ($pid=fork){ sleep($time); # $time is the time between updates of your database in seconds next } &updating_subroutine; exit } sub updating_subroutine{ eval{ # here you can insert lines, that read data from the file for the database to be updated with use Mysql; $db=Mysql->connect('host','database','login','pass'); $query=$db->query("insert into table (...) values ('$...', $query=$db->'$...', '$...', ...)"); # or $query=$db->query("update table set ...='$...', ...='$...', ..."); } } -------- |
|
#5
|
||||
|
||||
|
Assuming your webhost has a clue, they will quickly kill a permanently running script, and most likely warn you/kick you off. This is not an ideal solution. Find out if they support user crontab entries. If they don't, get a new host.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > using Perl to update MySQL automatically? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|