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

I have a piece of code that runs fine via command line but does not work from cron. Open a pipe to read a select from mysql. open multiple processes to read output from that select. Can somebody help out?
my $logdir = "piperead.$str.log"; open LOG, ">$logdir"; eval { open WP, '-|', "/apps/mysql/bin/mysql -hhost -pxxxxx -uxxxxx - +D mysearch_retention -q -e 'select entry_week, week_num, cbid,live, s +earching, entry_week_total, tot_search, ta, part from mysearch_part_t +rack' "; open RP1, '|-', "perl bin/retention_mywebsearch.pl " or die " +can't fork retention_mywebsearch.pl -$! \n"; open RP2, '|-', "perl report.pl" or die "can't fork report2.p +l -$! \n"; open RP3, '|-', "perl bin/retention_by_product_n2f.pl 1>/dev/ +null " or die "can't fork retention_mywebsearch.pl -$! \n"; open RP4, '|-', "perl bin/retention_by_product.pl 1>/dev/null + " or die "can't fork retention_mywebsearch.pl -$! \n"; open RP5, '|-', "perl bin/retention_mywebsearch_part.pl 1>/de +v/null" or die "can't fork retention_mywebsearch.pl -$! \n"; open RP6, '|-', "perl bin/retention_mywebsearch_specific_trac +k.pl 1>/dev/null" or die "can't fork retention_mywebsearch.pl -$! \n" +; }; if ( $@ ) { print LOG $@; print LOG "\n"; close LOG; exit 1; } #skip the header; my $header = <WP>; while (<WP>){ print RP1 $_; print RP2 $_; print RP3 $_; print RP4 $_; print RP5 $_; print RP6 $_; } close WP; close RP1; close RP2; close RP3; close RP4; close RP5; close RP6; close LOG;

Replies are listed 'Best First'.
Re: pipes don't work from cron
by Fletch (Bishop) on Feb 13, 2006 at 00:08 UTC

    My first guess would be to check that the relative paths are correct for the current working directory when run under cron (i.e. if bin/retention_by_product.pl lives somewhere other than under $HOME you might have problems).

      i am an idiot... that was exactly it. just the paths. thanks

        The Module FindBin gives you a variable called $FindBin::Bin which points to the path where the executed perlscript is; if you need a relative path like my $file = "./files/file.txt";, you can easily write instead:

        use FindBin; my $file = "$FindBin::Bin/files/file.txt";

        Best regards,
        perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

Re: pipes don't work from cron
by spiritway (Vicar) on Feb 12, 2006 at 23:37 UTC

    It would be really helpful if you would use '<code>' tags when you show code. The way you have it now, the first line in your eval goes way off the screen. With '<code>' tags, this would be formatted in a way that breaks the long lines.

      i apologize.
      my $logdir = "piperead.$str.log"; open LOG, ">$logdir"; eval { open WP, '-|', "/apps/mysql/bin/mysql -hhost -ppasswd -uhost - +D mysearch_retention -q -e 'select entry_week, week_num, cbid,live, s +earching, entry_week_total, tot_search, ta, part from mysearch_part_t +rack' "; open RP1, '|-', "perl bin/retention_mywebsearch.pl " or die " +can't fork retention_mywebsearch.pl -$! \n"; open RP2, '|-', "perl report.pl" or die "can't fork report2.p +l -$! \n"; open RP3, '|-', "perl bin/retention_by_product_n2f.pl 1>/dev/ +null " or die "can't fork retention_mywebsearch.pl -$! \n"; open RP4, '|-', "perl bin/retention_by_product.pl 1>/dev/null + " or die "can't fork retention_mywebsearch.pl -$! \n"; open RP5, '|-', "perl bin/retention_mywebsearch_part.pl 1>/de +v/null" or die "can't fork retention_mywebsearch.pl -$! \n"; open RP6, '|-', "perl bin/retention_mywebsearch_specific_trac +k.pl 1>/dev/null" or die "can't fork retention_mywebsearch.pl -$! \n" +; }; if ( $@ ) { print LOG $@; print LOG "\n"; close LOG; exit 1; } #skip the header; my $header = <WP>; while (<WP>){ print RP1 $_; print RP2 $_; print RP3 $_; print RP4 $_; print RP5 $_; print RP6 $_; } close WP; close RP1; close RP2; close RP3; close RP4; close RP5; close RP6; close LOG;