Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 30th, 2001, 01:04 PM
piksimoon piksimoon is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Posts: 6 piksimoon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!

Reply With Quote
  #2  
Old July 30th, 2001, 03:03 PM
Art Art is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Location: Belarus
Posts: 1 Art User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Art
I know how to do this, email me: aa@tut.by

Reply With Quote
  #3  
Old July 30th, 2001, 07:36 PM
Hero Zzyzzx's Avatar
Hero Zzyzzx Hero Zzyzzx is offline
11
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jul 2001
Location: Lynn, MA
Posts: 4,635 Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Days 23 h 44 m 19 sec
Reputation Power: 77
Send a message via AIM to Hero Zzyzzx
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.

Reply With Quote
  #4  
Old July 31st, 2001, 04:22 AM
Art Art is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Location: Belarus
Posts: 1 Art User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Art
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 ...='$...', ...='$...', ...");

}
}
--------

Reply With Quote
  #5  
Old July 31st, 2001, 09:25 AM
Hero Zzyzzx's Avatar
Hero Zzyzzx Hero Zzyzzx is offline
11
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jul 2001
Location: Lynn, MA
Posts: 4,635 Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Days 23 h 44 m 19 sec
Reputation Power: 77
Send a message via AIM to Hero Zzyzzx
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > using Perl to update MySQL automatically?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT