views:

253

answers:

1

I need to write a CGI program and it will display the output of a system command:

script.sh

echo "++++++"  
VAR=$(expect -c " spawn ssh -o StrictHostKeyChecking=no $USER@$HOST $CMD match_max 
100000 expect \"*?assword:*\" send -- \"$PASS\r\" send -- \"\r\" expect eof ") 
echo $VAR 
echo "++++++"

In CGI file:

my $command= "ksh ../cgi-bin/script.sh";
my @output= `$command`; 
print @output;

Finally, when I run the CGI file in unix, the $VAR is a very long string including \n and some delimiters. However, when I run on web server, the output is

++++++

++++++

So $VAR is missing when passing in the web interface/browser. I know maybe the problem is $VAR is very long string.

But anyway, is there anyway to solve this problem except writing the output to a file then retrieve it from browser?

Thanks if you are interested in my question.

+1  A: 

script.sh uses several environment variables: $USER, $HOST, $CMD and $PASS. The CGI environment will have different environment variables set than a login shell. You may need to set these variables from your CGI script before calling script.sh.

sjf
Thanks for pointing that.my $command= "ksh ../cgi-bin/script.sh $USER@$HOST $CMD ";But I still get the same output with the missing $VAR
aladine