Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I want to execute my perl script automatically on server. The code is on server and I want it to execute automatically daily at 3PM EST. I heard about some cron job and shell scripts which can do this, but not sure. Any help in this will be greatly regarded. Thanks, Ricks
  • Comment on How to automate my perl script on server

Replies are listed 'Best First'.
Re: How to automate my perl script on server
by aaron_baugher (Curate) on Aug 05, 2012 at 15:49 UTC

    Unfortunately, there are a few questions to answer before anyone can tell you how to do this. I'll try to break down some of the common situations:

    IF the server is a Unix-type, AND you can login via SSH or telnet and get a shell prompt, this is the simplest case: login and run crontab -e, and add a line like this one:

    0 3 * * * /path/to/my/script

    More info about the fields is available from man 5 crontab. This assumes that your user account has permission to use cron, which is usually the case. Anything your script outputs to SDTOUT or STDERR will be emailed to your local username on the server. If that mail won't reach you, add this line at the beginning of your crontab to specify an email address to send all outputs to:

    MAILTO:my@address

    If you don't have shell access, you may still be able to create a crontab, by uploading a CGI script like the following and executing it by going to it once in your browser:

    #!/bin/sh echo Content-type: text/html echo echo '0 3 * * * /path/to/my/program' | crontab echo 'crontab loaded, now delete this script'

    This will create a crontab belonging to the user the CGI script runs as, so this may not work if the server runs CGIs as some anonymous 'www' user. But if it uses something like suexec to run CGIs as their owner, it should create a crontab belonging to you.

    If you can't do that, your options get pretty limited. You could ask a server administrator to create the cron job for you, or for suggestions on how to do it yourself. Many CMSs like Wordpress and Drupal simulate cron by keeping their own schedule and checking it every time a request comes in, so you could create something like that, but that depends on your server being busy enough to trigger jobs close enough to the scheduled time.

    If it's a Windows server, I don't know much about that, except that I think they do have some scheduling facility.

    Aaron B.
    Available for small or large Perl jobs; see my home node.

Re: How to automate my perl script on server
by Corion (Patriarch) on Aug 05, 2012 at 15:29 UTC

    I recommend talking to your system administrator about cron.