- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: apache cgi-bin shell script number of argument...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2008 02:50 PM
06-24-2008 02:50 PM
apache cgi-bin shell script number of arguments
Running into a problem with a cgi-bin shell script determining number of arguments passed in from the request...
test case: if I use inetnet explorer to invoke a test cgi-bin shell script on HP-UX with apache using this syntax in the browser address bar:
http: //hpserver/cgi-bin/query/t.sh?1+
where test shell script is like this:
#!/bin/sh
set -f
echo "Content-type: text/plain"
echo ""
if [[ $# != 2 ]]
then
echo "error: should be 2 args. Number of args is $#"
echo "exiting..."
else
echo "OK, called with 2 args, |$1| |$2|"
echo "continuing..."
fi
... the result sent back to the browser is:
OK, called with 2 args, |1| ||
continuing...
I need the script to be able to determine valid number of arguments in requests. This request (above) should meet the test in the script, [[ $# != 2 ]] , shouldn't it?
and
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2008 07:14 PM
06-24-2008 07:14 PM
Re: apache cgi-bin shell script number of arguments
>if [[ $# != 2 ]]
This is not the proper syntax to check for integer compare. You are doing pattern matching. (It probably should still work.)
The correct syntax is:
if [[ $# -eq 2 ]]; then
>This request (above) should meet the test in the script,
It is almost as if you are getting "1" and then an empty string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2008 07:24 PM
06-24-2008 07:24 PM
Re: apache cgi-bin shell script number of arguments
> then an empty string.
At _least_ almost, I'd guess.
What happens with these?:
?a
?a+b
?+b
I'd guess that you'll see a pattern.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2008 10:38 PM
06-24-2008 10:38 PM
Re: apache cgi-bin shell script number of arguments
/cgi-bin/test-cgi?1+
...
argc is 1. argv is 1.
but
/cgi-bin/test-cgi?1+2
...
argc is 2. argv is 1 2.
because "+" means "
name= my name
the browser will convert this to
name=my+name
Note: when using forms (and what else?) you will specify the method (post or get), this will made the difference and all depends on this.
Depending on your needs you should handle the QUERY_STRING variable and disassemble the values from there.
Hope this helps!
Regards
Torsten.
__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.
__________________________________________________
No support by private messages. Please ask the forum!
If you feel this was helpful please click the KUDOS! thumb below!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2008 11:18 PM
06-24-2008 11:18 PM
Re: apache cgi-bin shell script number of arguments
a CGI script/program executed by the webserver is supplied with the CGI environment.
For HEAD and GET requests any parameters passed to the CGI script will be available in the environment variable QUERY_STRING.
The common method thus is to parse and decompose as well as "urldecode" the parameters from there.
For all sorts of programming/scripting languages there exist CGI libraries/modules that should be used instead of (re)implementing the parameter parsing and other common CGI stuff (e.g. providing correct HTTP response headers) oneself, because this is prone to errors and inadvertent security holes.
However, if you cannot resist the specs should be consulted, e.g. http://www.ietf.org/rfc/rfc3875
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2008 05:07 AM
06-25-2008 05:07 AM
Re: apache cgi-bin shell script number of arguments
this script is test case, to demonstrate problem in production scripts called by programs (not user sitting at keyboard/web browser). Called several thousand times per day by programs on several different computers. Also, for debug, I am reproducing the problem by calling from web browser. Scripts should always be called with 2 arguments, but I noticed sometimes they get callled mistakenly with one arg and a +, and script fails to take the error exit.
?a - looks like 1 arg.
?a+b - looks like 2 args. This is how all of the correct (99.9%) calls look.
?+b - can't try it right now. (I'm not at work. I'm on "vacation" 'til Monday.)
When I get back to this on Monday I'll look into the cgi environment variables, esp. QUERY_STRING.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2008 10:56 AM
07-10-2008 10:56 AM
Re: apache cgi-bin shell script number of arguments
However, the CGI QUERY_STRING variable does show "...1+", so I will parse that.