?
Solved

How to schedule perl program as batch job

Posted on 2007-07-31
14
Medium Priority
?
563 Views
Last Modified: 2013-12-25
How do i schedle a perl script as a batch job.  It uses curl to connect to web servers and get the html for web pages.

I have windows xp machine and active state perl 5.8.  I want to schedule the program to run every minute.

Also, is there a way to track that the program ran and see the results it received?
0
Comment
Question by:munzer
  • 5
  • 5
  • 3
  • +1
14 Comments
 
LVL 28

Expert Comment

by:FishMonger
ID: 19606536
>> I want to schedule the program to run every minute.

You use the Windows Task Scheduler:
Start -> Settings -> Control Panel -> Scheduled Tasks

>> Also, is there a way to track that the program ran and see the results it received?

You'll need to handle that in the Perl script.  The most common method would be to generate log entries at each stage of the script.
0
 
LVL 17

Expert Comment

by:mjcoyne
ID: 19608226
Are you sure you want to be hitting each server 1,440 times a day?  I'd be pretty pissed at you if I saw you doing that (which I obviously could, since such things are logged on the server end)...

Are the pages so dynamic that you need to check them every minute?
0
 
LVL 39

Accepted Solution

by:
Adam314 earned 1000 total points
ID: 19609804
Depending on how quickly the perl program runs through, you might not want to use windows scheduler.  If the script might take more than 60 seconds to run, you would be better off just having the perl program wait 60 seconds when it is finished, and restart.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:munzer
ID: 19614337
1. I did try to schedult using windows scheduler. It only allows you to do minimum every 24 hours. DO I also select just the name of the program.

2. I do not want to really do it 1440 times. I just want to see if http is reliable or not for sending messages back and forth using CURL and PERL.

3.  How does concurrency control work in perl. Let us say I scheduled it every minute and the program took 3 minutes to run. Is it going to start another instance of the program every minute. I really want it the program to run only once so if the batch job runs and finds that other process of same program is running  I do nott want it to  run.
0
 
LVL 28

Expert Comment

by:FishMonger
ID: 19614418
When creating the scheduled task, you can go into the advanced property settings and set it to 1 minute.

If you think that the script will take longer to run than the time between runs, then you should use Perl's sleep command in the script instead of using the task scheduler (which is what Adam was suggesting).  
0
 
LVL 39

Expert Comment

by:Adam314
ID: 19617505
For your number 2... If the webserver is up, you shouldn't have a problem.  
Are you planning on making a bunch of tests, and looking for how many are successful?

For your number 3...perl by itself will let a bunch of processes start, all running the same script.  The task scheduler has an option to kill a task if it runs to long, or kill the previous task when you start a new one - but i don't think that is what you want.

If you let us know what it is you are trying to do, we can help you get the best solution.  I don't think the task scheduler is going to be it though.
0
 

Author Comment

by:munzer
ID: 19632226
1. I tried the advance tab and it did work to schedule every minute. However my tasks are not getting run because I get this
"The new task has been created but the task may not run because account information could not be set. The specific error is 0x80070005: acces is denied.
Try using the task page button to locate the application

Is this related to the password i enter. I am not sure if it is correct or not. I may have forgotten it.

2. What I am trying to do is described here:

I  want to implement a client application that uses PERL and CURL to send messages via http from one remote server to another oracle database server. THe database will query the database or update the database and send the results back to the perl/http client. perl scripts on the remote server will be running continuously and perform file management on the server based on the XML data coming out from the database.  I am going to format db output as an XML because it is easier to parse by perl on the other server.

When perl runs on theremote server, i want to ensure that only one instance of the program is runnning. I do nto want two programs running doing the same stuff. It will be like two people writing one program and there is no concurrency.
0
 
LVL 39

Expert Comment

by:Adam314
ID: 19639781
For 1: You need to enter a username and password.  This will be the user that you want the script to run as.  However, I don't think the task scheduler is what you want to use.

You would probably be better with something like:
while(1) {
    #Do all of your stuff here
    sleep(60);    #wait 60 seconds
}
0
 

Author Comment

by:munzer
ID: 19643205
how do i use this while statement? Is this a valid dos prompt command that schedules a program job.
0
 
LVL 39

Expert Comment

by:Adam314
ID: 19647116
The code is to go into a perl program.  The perl program would be started only once, and it would never end.  You would then not use the scheduler.
Do you have the program that connects to the webserver and does whatever it needs to?  If so, you would put that code in the place "#Do all of your stuff here", and wrap the while loop and sleep around it.
0
 

Author Comment

by:munzer
ID: 19651092
Here is a sample perl program. is this what you mean.

while(1) {

 use WWW::Curl::Easy;
   my $curl = new WWW::Curl::Easy;
    $curl->setopt(CURLOPT_URL, 'http://oook.de');
    $curl->perform;
    my $err = $curl->errbuf;
    my $info = $curl->getinfo(CURLINFO_HTTP_CODE);
print $info;

   sleep(60);    #wait 60 seconds
}
0
 
LVL 28

Assisted Solution

by:FishMonger
FishMonger earned 1000 total points
ID: 19651166
Yes, but you should move a few of those lines outside of the loop.

use WWW::Curl::Easy;
my $curl = new WWW::Curl::Easy;
$curl->setopt(CURLOPT_URL, 'http://oook.de');

while(1) {
    $curl->perform;
    my $err = $curl->errbuf;
    my $info = $curl->getinfo(CURLINFO_HTTP_CODE);
    print $info;

    sleep(60);    #wait 60 seconds
}
0
 

Author Comment

by:munzer
ID: 19721556
I did run it and it did work with the sleep.

Is there any difference between using O/S to schedule or have it done internally using perl?

The other question, if this perl program took 2 minutes to run would it start another process after 60 seconds or it will wait till the original one is done.

I am trying to understand how you do concurrency control using perl. I want to make sure only one instance of the process is running at one time.
0
 
LVL 39

Expert Comment

by:Adam314
ID: 19730566
Using the OS to schedule:
1. The OS starts the program
2. It runs to completion, and the program exits
3. repeat at 1.... but the OS may check that the previous instants of the program has exited first, or may check it's return value.
The OS doesn't care about how long it takes to run the program.  It uses the schedule to determine when to start the program.

Using sleep:
1. The program is started
2. The program does what it needs
3. The program sleeps
4. repeat at 2
The program is only started once.  The sleep will set the time from finishing one time to beginning the next time.

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question