Link to home
Start Free TrialLog in
Avatar of saibsk
saibsk

asked on

running shell script inside a cgi script

I have a cgi script written using shell scripting. I want to execute another shell script inside the cgi script to setup the global environment.

Inside the CGI script

logFileName=${LOGSDIR}/info.log

. /scripts/global_setup.env


Inside the global_setup.env

SCRIPTDIR=monitor/scripts
LOGSDIR=monitor/logs

But I am not able to run the env script inside the cgi script as shown above. Could you please advise?
Avatar of amit_g
amit_g
Flag of United States of America image

What happens? Do you get any error? Make sure to give same permissions to this script as the cgi script.
Did you mean to do

. /scripts/global_setup.env

logFileName=${LOGSDIR}/info.log
Avatar of saibsk
saibsk

ASKER

global_setup.env has the same perms as the cgi script. And I did make the changes as above. When I try executing the cgi script through the console it works fine. I executed using the command ksh global_setup.env. But on the browser it throws an http 500 internal server error. I dont have access to the error log.
500 is very generic error but it could be due to the fact that you are trying to access ${LOGSDIR} before it is set. That statement would probably not throw any error but it would set the logFileName incorrectly and that may later produce error. Change the order of these statements as suggested by ozo i.e. invoke the global_setup.env before setting logFileName.

Avatar of saibsk

ASKER

i made the change. Throws the same error.
Does a simple cgi script work fine? A simple script as simple as

echo "Hello World"

?
Avatar of saibsk

ASKER

if I remove the line in cgi script the cgi script works fine
Which line? The one that calls /scripts/global_setup.env? If so it must be something to do with permissions. Do

ls -l /full/path/to/cgifile
ls -l /scripts/global_setup.env

and confirm same permissions on both. You may have to verify list access control list also in case ls -l shows same permissions. Use lsacl -l filename to verify list access contol.
Avatar of saibsk

ASKER

I did check ls -l for the env script and cgi script it shows 777 for both. Additionally for the command lsacl -l it shows up this message. ksh: lsacl:  not found.
Is there anything else inside
/scripts/global_setup.env
?

is there anything else Inside the CGI script?
Where are those 2 files relative to each other? Also does global_setup.env contain only the 2 statements that you showed?
Avatar of saibsk

ASKER

Actuall I want to globalize the environment so instead of setting these two lines in each file:
SCRIPTDIR=monitor/scripts
LOGSDIR=monitor/logs

I want to write a shell script which contains these lines. And execute that in the cgi script.
Currently i have made the change in the env script just to have this code
#!/bin/ksh

echo Content-type: text/html
echo "I am inside GLOBAL"

CGI script code:
#!/bin/ksh


echo Content-type: text/html

. /apps/SunOne/web61sp2/docs/coe/coe_monitor/scripts/coeGlobal.env &

Yet it shows up with the 500 error. Probably issue with the invocation of the env script.
Please advise
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

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
try

echo Content-type: text/html
echo
. /apps/SunOne/web61sp2/docs/coe/coe_monitor/scripts/coeGlobal.env