perl in crontab

Discussion in 'Perl Misc' started by news.hinet.net, Sep 17, 2004.

  1. This test can work when i run it anywhere.
    But the chdir seem does not work when i set it in crontab??
    ==============================================
    #!/usr/bin/perl

    chdir("/usr/local/admin/dir");
    system("tar zcvf test.tgz *");
     
    news.hinet.net, Sep 17, 2004
    #1
    1. Advertising

  2. news.hinet.net

    Sam Holden Guest

    On Fri, 17 Sep 2004 10:28:42 +0800,
    news.hinet.net <> wrote:
    > This test can work when i run it anywhere.
    > But the chdir seem does not work when i set it in crontab??
    >==============================================
    > #!/usr/bin/perl
    >
    > chdir("/usr/local/admin/dir");
    > system("tar zcvf test.tgz *");


    So test the return value and report the failure including the
    error message:

    chdir("/usr/local/admin/dir") or die "chdir failed: $!";
    system("tar zcvf test.tgz *")==0 or die "system failed: $!";


    --
    Sam Holden
     
    Sam Holden, Sep 17, 2004
    #2
    1. Advertising

  3. news.hinet.net wrote:

    > This test can work when i run it anywhere.
    > But the chdir seem does not work when i set it in crontab??


    Like Sam said - check for errors and print error messages.

    Also, look at the man pages for cron and crontab. Cron jobs run under a
    limited environment - most notably, the PATH variable is not likely the
    same as it is when you log into a shell.

    sherm--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
     
    Sherm Pendley, Sep 17, 2004
    #3
  4. news.hinet.net

    Shawn Corey Guest

    Hi,

    Two possible reasons. 1) Permissions: the crontab is running under a
    different user that cannot access the files. 2) No profile: cron does
    not run the user's .profile (or .cshrc and .login for csh) when it runs.
    Try using the full path for tar, system( "/usr/bin/tar ...

    news.hinet.net wrote:

    > This test can work when i run it anywhere.
    > But the chdir seem does not work when i set it in crontab??
    > ==============================================
    > #!/usr/bin/perl
    >
    > chdir("/usr/local/admin/dir");
    > system("tar zcvf test.tgz *");
    >
    >
     
    Shawn Corey, Sep 17, 2004
    #4
  5. news.hinet.net

    Ian Wilson Guest

    OT Re: perl in crontab

    news.hinet.net wrote:

    > This test can work when i run it anywhere.
    > But the chdir seem does not work when i set it in crontab??
    > ==============================================
    > #!/usr/bin/perl
    >
    > chdir("/usr/local/admin/dir");
    > system("tar zcvf test.tgz *");
    >
    >

    Also man tar, many tar implementations have a command line option for
    setting the initial directory for the operation.
     
    Ian Wilson, Sep 20, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vuk

    log4j & crontab

    Vuk, Nov 17, 2004, in forum: Java
    Replies:
    3
    Views:
    1,175
  2. rbt
    Replies:
    3
    Views:
    380
  3. Replies:
    2
    Views:
    590
  4. Martin Marcher

    crontab library

    Martin Marcher, Oct 24, 2007, in forum: Python
    Replies:
    0
    Views:
    375
    Martin Marcher
    Oct 24, 2007
  5. Matt Cluver

    Perl Script Not Running From Crontab.

    Matt Cluver, Apr 15, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    170
Loading...

Share This Page