Operating System - HP-UX
1827341 Members
5810 Online
109963 Solutions
New Discussion

using perl command in sh script cause error

 
SOLVED
Go to solution
kamal_15
Regular Advisor

using perl command in sh script cause error

hi all
i have hp-ux v 10.20
i writen sh script that interact with database.

this script contain perl command:
arch_date=`perl -e 'use POSIX qw(strftime);$ft=strftime"%d-%m-%y",localtime '$min';printf($ft)'`

i need this command to handle date.
may problem is:
when i execute this script through cron
the error messege appear in log file says
perl not found.

and when i execute this script manualy (from command line ) it works good.
i don't know what is different
please help

kamal
6 REPLIES 6
A. Clay Stephenson
Acclaimed Contributor

Re: using perl command in sh script cause error

It's very simple. Cron's environment is very sparse. You need to set and export any needed environment variables before calling Perl. In your case, PATH needs to be set to include the location of Perl.
If it ain't broke, I can fix that.
H.Merijn Brand (procura
Honored Contributor
Solution

Re: using perl command in sh script cause error

1. $min is undefined. passing that to localtime may cause *strange* results

why use POSIX?

# arch_date=`perl -e'@l=localtime;printf"%02d-%02d-%4d",$l[3],$l[4]+1,$l[5]%100'`

If you *realy* want POSIX:

# arch_date=`perl -MPOSIX=strftime -e'print strftime"%d-%m-%y",localtime'`

Note that POSIX is slow.

Enjoy, Have FUN! H.Merijn


Enjoy, Have FUN! H.Merijn
RAC_1
Honored Contributor

Re: using perl command in sh script cause error

That is because you did not give full path of perl. Give it and you would be fine.

Anil
There is no substitute to HARDWORK
kamal_15
Regular Advisor

Re: using perl command in sh script cause error

hi all
how can i edit cron env.
and when i edit my script with path of perl location.
the same error appear.

please help
A. Clay Stephenson
Acclaimed Contributor

Re: using perl command in sh script cause error

You can't directly edit the environment of cron but you can do something like this in the script called by cron:

#!/usr/bin/sh

export PATH=${PATH}:/opt/perl/bin

xxx=$(perl ....)

You may also need to add -Idir arguments to the Perl invocation so that it knows where to find any needed modules.
If it ain't broke, I can fix that.
kamal_15
Regular Advisor

Re: using perl command in sh script cause error

many thanks for all
my script works fine now
kamal