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?
saibskAsked:
Who is Participating?
 
TintinConnect With a Mentor Commented:
The HTTP MIME header needs a blank line after it.  Your script should read:

#!/bin/ksh
. /apps/SunOne/web61sp2/docs/coe/coe_monitor/scripts/coeGlobal.env

echo "Content-Type: text/plain"
echo
echo "SCRIPTDIR=$SCRIPTDIR"
0
 
amit_gCommented:
What happens? Do you get any error? Make sure to give same permissions to this script as the cgi script.
0
 
ozoCommented:
Did you mean to do

. /scripts/global_setup.env

logFileName=${LOGSDIR}/info.log
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
saibskAuthor Commented:
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.
0
 
amit_gCommented:
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.

0
 
saibskAuthor Commented:
i made the change. Throws the same error.
0
 
amit_gCommented:
Does a simple cgi script work fine? A simple script as simple as

echo "Hello World"

?
0
 
saibskAuthor Commented:
if I remove the line in cgi script the cgi script works fine
0
 
amit_gCommented:
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.
0
 
saibskAuthor Commented:
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.
0
 
ozoCommented:
Is there anything else inside
/scripts/global_setup.env
?

is there anything else Inside the CGI script?
0
 
amit_gCommented:
Where are those 2 files relative to each other? Also does global_setup.env contain only the 2 statements that you showed?
0
 
saibskAuthor Commented:
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
0
 
ozoCommented:
try

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

From novice to tech pro — start learning today.