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.


In reply to Re: How to automate my perl script on server by aaron_baugher
in thread How to automate my perl script on server by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.