executing bash script via CGI
up vote
0
down vote
favorite
everyone!
I have a trouble with executing .sh script from browser.
echo command works well. But when I store the value in variable and pass it to another script as an argument it does not work.
Appreciate any help.
Example:
Here I pass $XX to another script
if [ -z "$QUERY_STRING" ]; then
exit 0
else
XX=`echo "$QUERY_STRING" | sed -n 's/^.*val_x=([^&]*).*$/1/p' | sed "s/%20/ /g"`
if [ -z "$XX" ]; then
echo "X is empty"
else
echo "Processing..."
/sas/oljas_scripts/find_usage_of_tables.sh $XX
echo "Done"
fi
YY=`echo "$QUERY_STRING" | sed -n 's/^.*val_y=([^&]*).*$/1/p' | sed "s/%20/ /g"`
ZZ=`echo "$QUERY_STRING" | sed -n 's/^.*val_z=([^&]*).*$/1/p' | sed "s/%20/ /g"`
echo "val_x: " $XX
echo '<br>'
echo "val_y: " $YY
echo '<br>'
echo "val_z: " $ZZ
fi
linux bash shell scripting cgi
|
show 10 more comments
up vote
0
down vote
favorite
everyone!
I have a trouble with executing .sh script from browser.
echo command works well. But when I store the value in variable and pass it to another script as an argument it does not work.
Appreciate any help.
Example:
Here I pass $XX to another script
if [ -z "$QUERY_STRING" ]; then
exit 0
else
XX=`echo "$QUERY_STRING" | sed -n 's/^.*val_x=([^&]*).*$/1/p' | sed "s/%20/ /g"`
if [ -z "$XX" ]; then
echo "X is empty"
else
echo "Processing..."
/sas/oljas_scripts/find_usage_of_tables.sh $XX
echo "Done"
fi
YY=`echo "$QUERY_STRING" | sed -n 's/^.*val_y=([^&]*).*$/1/p' | sed "s/%20/ /g"`
ZZ=`echo "$QUERY_STRING" | sed -n 's/^.*val_z=([^&]*).*$/1/p' | sed "s/%20/ /g"`
echo "val_x: " $XX
echo '<br>'
echo "val_y: " $YY
echo '<br>'
echo "val_z: " $ZZ
fi
linux bash shell scripting cgi
How specifically does it not work? What is an example of a query string that you are handling?
– Amadan
Nov 12 at 7:32
Hi, Amadan. The script /sas/oljas_scripts/find_usage_of_tables.sh is for parsing log and it receives "some string" as an argument and returns some result. It works through console, but not from browser.
– Oljas
Nov 12 at 7:35
I want result to be returned to browser
– Oljas
Nov 12 at 7:35
If put echo "$XX" it returns user input value to browser.
– Oljas
Nov 12 at 7:37
"not from browser" does not answer "how specifically does it not work". Is there an error? Did you inspect the bottom of/var/log/apache2/error_log
? Does it output a wrong thing? What is it, if notuser_input
? Isuser_input
an exact format of the query string, or are you oversimplifying? (e.g. does it maybe have spaces?) What does it do, exactly?
– Amadan
Nov 12 at 7:40
|
show 10 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
everyone!
I have a trouble with executing .sh script from browser.
echo command works well. But when I store the value in variable and pass it to another script as an argument it does not work.
Appreciate any help.
Example:
Here I pass $XX to another script
if [ -z "$QUERY_STRING" ]; then
exit 0
else
XX=`echo "$QUERY_STRING" | sed -n 's/^.*val_x=([^&]*).*$/1/p' | sed "s/%20/ /g"`
if [ -z "$XX" ]; then
echo "X is empty"
else
echo "Processing..."
/sas/oljas_scripts/find_usage_of_tables.sh $XX
echo "Done"
fi
YY=`echo "$QUERY_STRING" | sed -n 's/^.*val_y=([^&]*).*$/1/p' | sed "s/%20/ /g"`
ZZ=`echo "$QUERY_STRING" | sed -n 's/^.*val_z=([^&]*).*$/1/p' | sed "s/%20/ /g"`
echo "val_x: " $XX
echo '<br>'
echo "val_y: " $YY
echo '<br>'
echo "val_z: " $ZZ
fi
linux bash shell scripting cgi
everyone!
I have a trouble with executing .sh script from browser.
echo command works well. But when I store the value in variable and pass it to another script as an argument it does not work.
Appreciate any help.
Example:
Here I pass $XX to another script
if [ -z "$QUERY_STRING" ]; then
exit 0
else
XX=`echo "$QUERY_STRING" | sed -n 's/^.*val_x=([^&]*).*$/1/p' | sed "s/%20/ /g"`
if [ -z "$XX" ]; then
echo "X is empty"
else
echo "Processing..."
/sas/oljas_scripts/find_usage_of_tables.sh $XX
echo "Done"
fi
YY=`echo "$QUERY_STRING" | sed -n 's/^.*val_y=([^&]*).*$/1/p' | sed "s/%20/ /g"`
ZZ=`echo "$QUERY_STRING" | sed -n 's/^.*val_z=([^&]*).*$/1/p' | sed "s/%20/ /g"`
echo "val_x: " $XX
echo '<br>'
echo "val_y: " $YY
echo '<br>'
echo "val_z: " $ZZ
fi
linux bash shell scripting cgi
linux bash shell scripting cgi
asked Nov 12 at 7:30
Oljas
166
166
How specifically does it not work? What is an example of a query string that you are handling?
– Amadan
Nov 12 at 7:32
Hi, Amadan. The script /sas/oljas_scripts/find_usage_of_tables.sh is for parsing log and it receives "some string" as an argument and returns some result. It works through console, but not from browser.
– Oljas
Nov 12 at 7:35
I want result to be returned to browser
– Oljas
Nov 12 at 7:35
If put echo "$XX" it returns user input value to browser.
– Oljas
Nov 12 at 7:37
"not from browser" does not answer "how specifically does it not work". Is there an error? Did you inspect the bottom of/var/log/apache2/error_log
? Does it output a wrong thing? What is it, if notuser_input
? Isuser_input
an exact format of the query string, or are you oversimplifying? (e.g. does it maybe have spaces?) What does it do, exactly?
– Amadan
Nov 12 at 7:40
|
show 10 more comments
How specifically does it not work? What is an example of a query string that you are handling?
– Amadan
Nov 12 at 7:32
Hi, Amadan. The script /sas/oljas_scripts/find_usage_of_tables.sh is for parsing log and it receives "some string" as an argument and returns some result. It works through console, but not from browser.
– Oljas
Nov 12 at 7:35
I want result to be returned to browser
– Oljas
Nov 12 at 7:35
If put echo "$XX" it returns user input value to browser.
– Oljas
Nov 12 at 7:37
"not from browser" does not answer "how specifically does it not work". Is there an error? Did you inspect the bottom of/var/log/apache2/error_log
? Does it output a wrong thing? What is it, if notuser_input
? Isuser_input
an exact format of the query string, or are you oversimplifying? (e.g. does it maybe have spaces?) What does it do, exactly?
– Amadan
Nov 12 at 7:40
How specifically does it not work? What is an example of a query string that you are handling?
– Amadan
Nov 12 at 7:32
How specifically does it not work? What is an example of a query string that you are handling?
– Amadan
Nov 12 at 7:32
Hi, Amadan. The script /sas/oljas_scripts/find_usage_of_tables.sh is for parsing log and it receives "some string" as an argument and returns some result. It works through console, but not from browser.
– Oljas
Nov 12 at 7:35
Hi, Amadan. The script /sas/oljas_scripts/find_usage_of_tables.sh is for parsing log and it receives "some string" as an argument and returns some result. It works through console, but not from browser.
– Oljas
Nov 12 at 7:35
I want result to be returned to browser
– Oljas
Nov 12 at 7:35
I want result to be returned to browser
– Oljas
Nov 12 at 7:35
If put echo "$XX" it returns user input value to browser.
– Oljas
Nov 12 at 7:37
If put echo "$XX" it returns user input value to browser.
– Oljas
Nov 12 at 7:37
"not from browser" does not answer "how specifically does it not work". Is there an error? Did you inspect the bottom of
/var/log/apache2/error_log
? Does it output a wrong thing? What is it, if not user_input
? Is user_input
an exact format of the query string, or are you oversimplifying? (e.g. does it maybe have spaces?) What does it do, exactly?– Amadan
Nov 12 at 7:40
"not from browser" does not answer "how specifically does it not work". Is there an error? Did you inspect the bottom of
/var/log/apache2/error_log
? Does it output a wrong thing? What is it, if not user_input
? Is user_input
an exact format of the query string, or are you oversimplifying? (e.g. does it maybe have spaces?) What does it do, exactly?– Amadan
Nov 12 at 7:40
|
show 10 more comments
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
The file you are trying to execute, /sas/oljas_scripts/find_usage_of_tables.sh
, is not executable for the web server. Currently, it is:
-rwxrw-r-- 1 sas sas 1540 Nov 12 12:58 find_usage_of_tables.sh
Which means sas
user can do everything, sas
group can read and write but not execute, and everyone else can just read. Notably, the web server needs to be able to both read and execute the file, and it is failing to do so.
Either set the file to be readable and executable to all (not recommended):
chmod 755 /sas/oljas_scripts/find_usage_of_tables.sh
or set the group of the file to be a group the web server is in, and set the group permissions of the file accordingly:
chmod 754 /sas/oljas_scripts/find_usage_of_tables.sh
chgrp www-data /sas/oljas_scripts/find_usage_of_tables.sh
You may need sudo
for the latter. Also, the web server's group name might not be www-data
- inspect your web server configuration, or read it off of process list like this answer suggests.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257583%2fexecuting-bash-script-via-cgi%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
The file you are trying to execute, /sas/oljas_scripts/find_usage_of_tables.sh
, is not executable for the web server. Currently, it is:
-rwxrw-r-- 1 sas sas 1540 Nov 12 12:58 find_usage_of_tables.sh
Which means sas
user can do everything, sas
group can read and write but not execute, and everyone else can just read. Notably, the web server needs to be able to both read and execute the file, and it is failing to do so.
Either set the file to be readable and executable to all (not recommended):
chmod 755 /sas/oljas_scripts/find_usage_of_tables.sh
or set the group of the file to be a group the web server is in, and set the group permissions of the file accordingly:
chmod 754 /sas/oljas_scripts/find_usage_of_tables.sh
chgrp www-data /sas/oljas_scripts/find_usage_of_tables.sh
You may need sudo
for the latter. Also, the web server's group name might not be www-data
- inspect your web server configuration, or read it off of process list like this answer suggests.
add a comment |
up vote
0
down vote
accepted
The file you are trying to execute, /sas/oljas_scripts/find_usage_of_tables.sh
, is not executable for the web server. Currently, it is:
-rwxrw-r-- 1 sas sas 1540 Nov 12 12:58 find_usage_of_tables.sh
Which means sas
user can do everything, sas
group can read and write but not execute, and everyone else can just read. Notably, the web server needs to be able to both read and execute the file, and it is failing to do so.
Either set the file to be readable and executable to all (not recommended):
chmod 755 /sas/oljas_scripts/find_usage_of_tables.sh
or set the group of the file to be a group the web server is in, and set the group permissions of the file accordingly:
chmod 754 /sas/oljas_scripts/find_usage_of_tables.sh
chgrp www-data /sas/oljas_scripts/find_usage_of_tables.sh
You may need sudo
for the latter. Also, the web server's group name might not be www-data
- inspect your web server configuration, or read it off of process list like this answer suggests.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
The file you are trying to execute, /sas/oljas_scripts/find_usage_of_tables.sh
, is not executable for the web server. Currently, it is:
-rwxrw-r-- 1 sas sas 1540 Nov 12 12:58 find_usage_of_tables.sh
Which means sas
user can do everything, sas
group can read and write but not execute, and everyone else can just read. Notably, the web server needs to be able to both read and execute the file, and it is failing to do so.
Either set the file to be readable and executable to all (not recommended):
chmod 755 /sas/oljas_scripts/find_usage_of_tables.sh
or set the group of the file to be a group the web server is in, and set the group permissions of the file accordingly:
chmod 754 /sas/oljas_scripts/find_usage_of_tables.sh
chgrp www-data /sas/oljas_scripts/find_usage_of_tables.sh
You may need sudo
for the latter. Also, the web server's group name might not be www-data
- inspect your web server configuration, or read it off of process list like this answer suggests.
The file you are trying to execute, /sas/oljas_scripts/find_usage_of_tables.sh
, is not executable for the web server. Currently, it is:
-rwxrw-r-- 1 sas sas 1540 Nov 12 12:58 find_usage_of_tables.sh
Which means sas
user can do everything, sas
group can read and write but not execute, and everyone else can just read. Notably, the web server needs to be able to both read and execute the file, and it is failing to do so.
Either set the file to be readable and executable to all (not recommended):
chmod 755 /sas/oljas_scripts/find_usage_of_tables.sh
or set the group of the file to be a group the web server is in, and set the group permissions of the file accordingly:
chmod 754 /sas/oljas_scripts/find_usage_of_tables.sh
chgrp www-data /sas/oljas_scripts/find_usage_of_tables.sh
You may need sudo
for the latter. Also, the web server's group name might not be www-data
- inspect your web server configuration, or read it off of process list like this answer suggests.
answered Nov 12 at 8:05
Amadan
127k13137190
127k13137190
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257583%2fexecuting-bash-script-via-cgi%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
How specifically does it not work? What is an example of a query string that you are handling?
– Amadan
Nov 12 at 7:32
Hi, Amadan. The script /sas/oljas_scripts/find_usage_of_tables.sh is for parsing log and it receives "some string" as an argument and returns some result. It works through console, but not from browser.
– Oljas
Nov 12 at 7:35
I want result to be returned to browser
– Oljas
Nov 12 at 7:35
If put echo "$XX" it returns user input value to browser.
– Oljas
Nov 12 at 7:37
"not from browser" does not answer "how specifically does it not work". Is there an error? Did you inspect the bottom of
/var/log/apache2/error_log
? Does it output a wrong thing? What is it, if notuser_input
? Isuser_input
an exact format of the query string, or are you oversimplifying? (e.g. does it maybe have spaces?) What does it do, exactly?– Amadan
Nov 12 at 7:40