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

I've a script which i want to schedule to run at 10:00 AM every morning using cron. I have no prior idea about using cron. Firstly I want to know whether it is possible to schedule the running of a perl script using cron or not.If it is possible kindly help me out. thanx in advance.
#!/usr/bin/perl use strict; use warnings; use LWP::Simple; use Email::Send; use Email::Send::Gmail; use Email::MIME::Creator; use IO::All; my $url = "http://abcd.com/search?q=%22MB%22&t=blogs&f=csv"; my $file = "/Users/Abc/Desktop/MB.csv"; my $status = mirror($url,$file); die "Cannot retrieve $url" unless is_success($status); my $email = Email::MIME->create( header => [ From => 'abcd@gmail.com' To => 'abc1@gmail.com', Subject => 'ABCD', ], attributes => { filename =>"MB.csv", content_type =>"application/csv", disposition =>"attachment", Name =>"/Users/Abc/Desktop/MB.csv", }, body => io( "/Users/Abc/Desktop/MB.csv" )->all, ); my $sender = Email::Send->new( { mailer => 'Gmail', mailer_args => [ username => 'abcd@gmail.com', password => '1234qwerty', ] } ); eval { $sender->send($email) }; die "Error sending email: $@" if $@;

Replies are listed 'Best First'.
Re: Perl script using cron
by Corion (Patriarch) on Mar 16, 2010 at 09:05 UTC

    What have you done so far to learn about cron? It's quite possible to run Perl programs through Cron, so I'm not sure how to help you more.

    Usually, you can also configure your crontab entries to set up the recipient of the email directly. cron will then send mail to the configured account using the local mail sending mechanism.

Re: Perl script using cron
by JavaFan (Canon) on Mar 16, 2010 at 10:54 UTC
    Firstly I want to know whether it is possible to schedule the running of a perl script using cron or not.
    Cron doesn't care at all in which language your program is written.
    If it is possible kindly help me out.
    Actually, how to use cron isn't a Perl question. Have you read the cron and crontab manual pages?
Re: Perl script using cron
by ssandv (Hermit) on Mar 16, 2010 at 17:40 UTC

    You might also look at at depending on what your use case is. at inherits almost all of its invoker's environment, while cron gets pretty near none of it, which can lead to some frustration. In any event, the code on the end of your post is entirely superfluous, and as others have said, how to get cron working isn't a Perl issue at all. Cron pays no attention whatsoever to details of the commands you give it, it just runs them at the specified time in a clean environment. If it's an executable and properly constructed, it will execute. If it's not, it won't. Also of course, the standard advice for stuff like this--try it and see what happens.

Re: Perl script using cron
by ahmad (Hermit) on Mar 17, 2010 at 02:00 UTC

    You'll have to make sure that your script has the right permissions to run through the cron.

    Then simply add the following to crontab to make it run every day at 10 AM

    * 10 * * * /path/to/your/script.pl

    You might want your cron to suppress output, which make the line above as follows:

    * 10 * * * /path/to/your/script.pl > /dev/null 2>&1
      thanx alot .. it worked..