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

Hopefully I can make this question clear and succinct...

I'm trying to get a script using Net::Twitter to work from cron. (Ubuntu KK). Works fine elsewise, but naturally I've got to make all sorts of adjustments to get it to run from cron. I've added libs and that got me so far.

Now it seems Moose won't run because it requires the Scalar::Util 'weaken' function which, in cron's environment, doesn't work because it's not using the 'XS version'.

I changed the shebang line to use perl5. Still no go. The question is: How do I get my script to run the XS version of Scalar::Util in cron's environment?

Also, you may find my understanding and vocabulary ever so patchy because I'm learning all of this by trial and error.

  • Comment on Getting Moose &/or Net::Twitter to work from cron.

Replies are listed 'Best First'.
Re: Getting Moose &/or Net::Twitter to work from cron.
by Anonymous Monk on Mar 28, 2010 at 17:18 UTC
    When its working do
    $cat whenitsworking.pl print qq!use lib qw( @INC );\n!; print qq!local \$ENV{q($_)} = q($ENV{$_});\n! for keys %ENV;
    then insert that into your cron program
      Thank you. That's a little bit over my head though. I'm guessing it has something to do with making sure the environment is right for cron. Which I've been doing by adding libs.

      I think the problem might actually be that the XS version of Scalar::Util somehow needs to be run through the C compiler. Which cron can't get to. I think.

      I'm trying Net::Twitter::Lite now. So as to bypass the use of Moose altogether.

        Thank you. That's a little bit over my head though. I'm guessing it has something to do with making sure the environment is right for cron. Which I've been doing by adding libs.

        The enviroment is a variable, in perl you access it through %ENV.

        I think the problem might actually be that the XS version of Scalar::Util somehow needs to be run through the C compiler. Which cron can't get to. I think.

        No, not at all. Once a module is installed, its available. When installing it might need a compiler, like Scalar::Util, but after it is installed, compiler isn't involved.

Re: Getting Moose &/or Net::Twitter to work from cron.
by CountZero (Bishop) on Mar 28, 2010 at 18:20 UTC
    It looks as if cron is running another Perl perhaps?

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      Yeah, probably. I didn't think that would be a problem. I'll try disabling all the perl scripts I've got running from cron.
Re: Getting Moose &/or Net::Twitter to work from cron.
by Zeno Izen (Sexton) on Mar 28, 2010 at 19:13 UTC
    ... well, Net::Twitter::Lite works well enough for my current purposes. I'll keep tinkering with this, though, for my own edification. Thank you for your help. :)
      Be sure to pay attention to the user cron is running as. I ran into similarly bizarre behavior with a CGI I wrote when I realized my "at" command, executed from within it, was running as "nobody" and didn't have access to what it needed. Not the same but similar.

      You could also try spawning a bash shell and running it from within that, instead of directly, ie.

      bash myperlscript.pl

      instead of just:

      myperlscript.pl

      Also check /var/log/cron for errors.