Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Getting input and changing variable? Post 302875129 by Corona688 on Monday 18th of November 2013 02:23:29 PM
Old 11-18-2013
Your other script has to process ${QUERY_STRING} and extract the variable from it. ${QUERY_STRING} will contain values like
Code:
VAR1=value1&VAR2=value2&VAR3=value3

just like you'd see appended to the end of the webpage.

I process it like this:

Code:
# Just an example/test, you should not set QUERY_STRING yourself
QUERY_STRING="a=b&c=d&g=h&i=j"

OLDIFS="$IFS"
IFS="&" # Split strings upon & instead of space
        set -- ${QUERY_STRING} # Set $1="a=b", $2="c=d", $3="g=h", $4="i=j"
        while [ "$#" -ne 0 ] # Loop until we're all out of $1 $2 $3 ...
        do
                IFS="=" read NAME VAL <<EOF
${1}
EOF
                IFS="=" read CGI_"$NAME" VAL <<EOF
${1}
EOF
                shift # Get rid of $1 so $1="c=d", $2="g=h", ...
        done

IFS="$OLDIFS" # Return to default splitting behavior

echo ${CGI_a}
echo ${CGI_c}
echo ${CGI_g}

You will end up with variables like CGI_a, CGI_c, CGI_g, and so forth. The CGI_ prefix is so that web users can't accidentally (or worse, maliciously) change important, special variables like PATH in your script... This way if someone tries, all they'll set is CGI_PATH.

All the read junk is just a tricky way of setting random variable names without resorting to eval. This prevents malicious web users from feeding `rm -Rf ~/ into your code...

Last edited by Corona688; 11-18-2013 at 03:31 PM..
 

10 More Discussions You Might Find Interesting

1. Programming

Changing stdin from file redirection to console input

Hi I am doing file redirection at console for use by my binary. %console%> bin &lt inputfile After reading in the entire file, I want my program to continue taking input from the console. So essentially I want to redirect stdin back to console. But I cant figure out how to do it. I am... (4 Replies)
Discussion started by: nauman
4 Replies

2. Shell Programming and Scripting

IFS changing the variable value

Hi, I have a while read loop that reads files in a directory and process. The files have spaces in between, so I have the IFS=\n to to read the whole line as one file name. The read works fine but I have a problem with another variable that I set in the beginning of the script. The variable... (1 Reply)
Discussion started by: pvar
1 Replies

3. UNIX for Dummies Questions & Answers

send output of a file as input for changing date

Hi, Please help me out on this one. I want to send the output of a file as input for changing the date using date command. Example, i have a file date.txt whose contents are 081014462009 I need to use the date in that file as input for date command. I tried cat date.txt | date ; but it... (2 Replies)
Discussion started by: foxtron
2 Replies

4. Shell Programming and Scripting

Create Multiple files by reading a input file and changing the contents

Being new to this area .I have been assigned a task which i am unable to do . Can any one please help me . Hi I have requirement where i have input file XYZ_111_999_YYYYMMDD_1.TXT and with header and series of Numbers and Footer. I want to create a mutiple output files with each file having a... (2 Replies)
Discussion started by: bhargavkr
2 Replies

5. Shell Programming and Scripting

Changing variable name in for loop

Hi All please help if possible. I am a Unix novice. I have a similar question to the one posted by yonderboy at about a year ago. However his solution does not work for me. The pseudo code for my problem is as follows: for fund in 1 2 3 4 if (FTP is successfully) then FILE_SENT_fund... (2 Replies)
Discussion started by: Seether
2 Replies

6. Shell Programming and Scripting

Input value changing into 0

Hi, I am getting a strange problem in my production environment. Line in input file: Code: while read myline do echo $myline >> /home/aauytrf/PARM_FILE_NM.bak fi done < /home/aauytrf/PARM_FILE_NM.prm Output: 0 Here the input line is becoming 0. This is not happening to... (11 Replies)
Discussion started by: niba
11 Replies

7. Shell Programming and Scripting

Changing the variable using awk?

Dear all, I have kind of used both the awk/sed command and found them really useful. But at the necessity I am having right now, I need help. Actually, I would like to do the following in file script.sh PATH535="/eos/uscms/store/user/pooja04//analysis2012/535/mc/summer12/002/tt/" ... (2 Replies)
Discussion started by: emily
2 Replies

8. Shell Programming and Scripting

XML variable for input in same input file

Dear All , i stuck in one problem executing xml .. i have input xml as <COMMAND name="ARRANGEMENT.WRITE" timestamp="0" so="initial"> <SVLOBJECT> <LONG name="CSP_PMNT_ID" val="-1"/> <MONEY name="CSP_CEILING" amount="0.0" currency="AUD"/> ... (6 Replies)
Discussion started by: arvindng
6 Replies

9. UNIX for Dummies Questions & Answers

Changing Path Variable

Blank Blank Blank (11 Replies)
Discussion started by: pvibien
11 Replies

10. UNIX for Advanced & Expert Users

Passing variable as input & storing output in other variable

I have a below syntax its working fine... var12=$(ps -ef | grep apache | awk '{print $2,$4}') Im getting expected output as below: printf "%b\n" "${VAR12}" dell 123 dell 456 dell 457 Now I wrote a while loop.. the output of VAR12 should be passed as input parameters to while loop and results... (5 Replies)
Discussion started by: sam@sam
5 Replies
HOBBITGRAPH.CGI(1)					      General Commands Manual						HOBBITGRAPH.CGI(1)

NAME
hobbitgraph.cgi - CGI to generate Xymon trend graphs SYNOPSIS
hobbitgraph [options] DESCRIPTION
hobbitgraph.cgi is invoked as a CGI script via the hobbitgraph.sh CGI wrapper. hobbitgraph.cgi is passed a QUERY_STRING environment variable with the following parameters: host Name of the host to generate a graph for service Name of the service to generate a graph for disp Display-name of the host, used on the generated graphs instead of hostname. graph Can be "hourly", "daily", "weekly" or "monthly" to select the time period that the graph covers. first Used to split multi-graphs into multiple graphs. This causes hobbitgraph.cgi to generate only the graphs starting with the "first'th" graph and continuing for "count". count Number of graphs in a multi-graph. upper Set the upper limit of the graph. See rrdgraph(1) for a description of the "-u" option. lower Set the lower limit of the graph. See rrdgraph(1) for a description of the "-l" option. graph_start Set the starttime of the graph. This is used in zoom-mode. graph_end Set the end-time of the graph. This is used in zoom-mode. action=menu Generate an HTML page with links to 4 graphs, representing the hourly, weekly, monthly and yearly graphs. Doesn't actually gen- erate any graphs, only the HTML that links to the graphs. action=selzoom Generate an HTML page with link to single graph, and with JavaScript code that lets the user select part of the graph for a zoom-operation. The JavaScript invokes hobbitgraph.cgi with "action=showzoom" to generate the zoomed graph webpage. action=showzoom Generate HTML with a link to the zoomed graph image. This link goes to an "action=view" invocation of hobbitgraph.cgi. action=view Generate a single graph image. OPTIONS
--config=FILENAME Loads the graph configuration file from FILENAME. If not specified, the file $BBHOME/etc/hobbitgraph.cfg is used. See the hobbit- graph.cfg(5) for details about this file. --env=FILENAME Loads the environment settings defined in FILENAME before executing the CGI. --rrddir=DIRECTORY The top-level directory for the RRD files. If not specified, the directory given by the BBRRDS environment is used. --save=FILENAME Instead of returning the image via the CGI interface (i.e. on stdout), save the generated image to FILENAME. --debug Enable debugging output. ENVIRONMENT
QUERY_STRING Provided by the webserver CGI interface, this decides what graph to generate. FILES
hobbitgraph.cfg: The configuration file determining how graphs are generated from RRD files. SEE ALSO
hobbitgraph.cfg(5), xymon(7), rrdtool(1) Xymon Version 4.2.3: 4 Feb 2009 HOBBITGRAPH.CGI(1)
All times are GMT -4. The time now is 01:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy