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

I have a script that reads in the files of a directory, looks for specific files (based upon the filename), then prints those files out. Now in the .profile of the user, I have an environment variable called PDPRINTER set, so that I can use a special command to print out the report double-sided. When I run this script from the command line, I have absolutely no problems. However, when I run it from cron, it doesn't work(i.e. the files don't print, although the directory listing that I print using lpr does). The O.S. is HP-UX 11.0 with Perl 5.6.1
#!/opt/perl5/bin/perl -w use strict; use File::Slurp; my $DIR="/home/mis/ftpstore"; my @Files=read_dir($DIR); my $file; @Files=sort{$a cmp $b}@Files; system("ls -l $DIR/Unity*.prpt | lpr"); foreach $file(@Files){ if($file=~/Unity\d{3}\.prpt/){ ## This command is a specialized command for the ## HP Distributed Print Service. system("pdpr -x sides=2 $DIR/$file"); } }
Any suggestions or ideas are welcome. Thanks.

TStanley
--------
There's an infinite number of monkeys outside who want to talk to us
about this script for Hamlet they've worked out
-- Douglas Adams/Hitchhiker's Guide to the Galaxy

Replies are listed 'Best First'.
Re: Not accepting the environment variable
by blakem (Monsignor) on Oct 25, 2001 at 05:33 UTC
Re: Not accepting the environment variable
by Zaxo (Archbishop) on Oct 25, 2001 at 06:34 UTC

    By default cron runs with an empty environment. You can set PDPRINTER=1 (and any other environment you need) at the top of your crontab.

    After Compline,
    Zaxo

Re: Not accepting the environment variable
by davis (Vicar) on Oct 25, 2001 at 12:12 UTC
    From the HP-UX 11.0 crontab(1) man page:
          cron supplies a default environment for every shell, defining:
    
               HOME=user's-home-directory
               LOGNAME=user's-login-id
               PATH=/usr/bin:/usr/sbin:.
               SHELL=/usr/bin/sh
    
          Users who desire to have their .profile executed must explicitly do so
          in the crontab entry or in a script called by the entry.
    
Re: Not accepting the environment variable
by higle (Chaplain) on Oct 25, 2001 at 05:58 UTC
    In particular, you can fix the problem from within your script by setting the environment variable:
    $ENV{'PDPRINTER'} = $foo;
    Try that, and it should work.
    #------------- perl -e 's=$;$/=$\;W=i;$\=$/;s;;XYW\\U$"\;\);sig,$_^=$[x5,print;'
Re: Not accepting the environment variable
by TStanley (Canon) on Oct 25, 2001 at 21:10 UTC
    After trying the suggestions of blakem and higle without success, I finally tried it as a shell script and sourced in another file with the parameters I needed, and it worked.

    As much as I like to use Perl, sometimes all you need is a simple knife instead of a Swiss Army chainsaw :-)

    TStanley
    --------
    There's an infinite number of monkeys outside who want to talk to us
    about this script for Hamlet they've worked out
    -- Douglas Adams/Hitchhiker's Guide to the Galaxy