Link to home
Start Free TrialLog in
Avatar of saibsk
saibsk

asked on

invoke shell script from Perl

I am trying to execute a shell script which is giving me the following error.
system ksh check_xmlExtracts.ksh client638 source cl638 failed: 256 at run_dcm_scripts.pl line 12, <FH> line 1.

Perl script:

@args=("ksh", "check_Extracts.ksh","$array[0]","$array[4]", "$array[2]");
system(@args)==0
        or die "system @args failed: $?";

where @array=(client638    qsapp01     cl638       ATG    source)

Please advise.
Avatar of ozo
ozo
Flag of United States of America image

What does check_Extracts.ksh do?
when would it return a non zero status?
Avatar of saibsk
saibsk

ASKER

instanceName=$1
source=$2
clientInstance=$3

portNum=4${instanceName##[a-z]*[a-z]}

results=`isql -Sservername -Uuser -Ppassword <<EOF
set nocount on
go
select ipaddress from client_info where instancename = "$instanceName"
go
EOF`

ip=`echo "$results" | tail +3`

echo "IP:$ip\n";
echo "$portNum\n";
ssh $ip "grep ":$portNum" *> "$clientInstance$source"_xml_extract.out

THis is the check_Extracts script. WHen I invoke this script with the directly supplying the inputs it works fine but when I invoke the shell script thru Perl with the input @array=(client638    qsapp01     cl638       ATG    source) it throws the above error
What is the status in $? when you invoke this script with the directly supplying the inputs ?
Does anything print when you invoke it from Perl?
is "$clientInstance$source"_xml_extract.out creates when you invoke it from perl?
Avatar of saibsk

ASKER

The $? is 256 when I invoke from Perl.
But when I execute directly the $clientInstance$source"_xml_extract.out is created with the data.

But when I try from Perl even the file is not created.

How do I check $? when I direclty execute the shell script.
Avatar of saibsk

ASKER

when I printed the $? in my shell script it is printing 1. That means is my script failiing but t does generate the file with data. Please advise.
If the script does what you want despite returning a non-zero status, then perhaps you want to ignore the status.
Unless the status signifies something you don't wantin which case you may want to adjust  the ksh script
It looks like the last command was a grep, which would return status 1 if the line is not found
Is that a problem?
Avatar of saibsk

ASKER

It is actually create the file even though the perl script dies when I invoke the shell script thru Perl. I don't understand what is wrong.
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial