Passing variable and returning


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing variable and returning
# 1  
Old 01-27-2012
Passing variable and returning

1. I setup a website on html with a single text box and a submit button.
2. When the user enters the data into the text box and clicks submit - The output is displayed on a php site I setup as well

*Clearly I don't know much of PHP or HTML*

So now, I want to.... take this output, convert it into variable $IP_ADDRESS, send this variable to an outside script and then output the generated data on the same php site.

This is what I have so far.

==

Code:
<?php
$IP_ADDRESS = $_POST['IP_ADDRESS'];


if( empty($IP_ADDRESS )) {
echo "<h2>Enter some data</h2>\n" ;
die ("Click Back to start again.");
}

echo "Output:<br><br>";
echo $IP_ADDRESS;
?>

//It works up to here
Code:
<?php
system('bash ./cnamegenerate.sh', $IP_ADDRESS);
?>

===

Code:
[root]$ cat cnamegenerate.sh 
echo $IP_ADDRESS;


Last edited by Franklin52; 01-30-2012 at 04:49 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 01-30-2012
Code:
$ cat cnamegenerate.sh
 
if [[ ! -z ${1} ]]; then
   IP_ADDRESS="${1}"
else
   echo -e "Usage:\n\t${0} <IP_ADDRESS>"
   exit 1
fi
 
echo ${IP_ADDRESS}

For the PHP
PHP Code:
<?php
$IP_ADDRESS 
$_POST['IP_ADDRESS'];
 
 
if( empty(
$IP_ADDRESS )) {
echo 
"<h2>Enter some data</h2>\n" ;
die (
"Click Back to start again.");
}
 
echo 
"Output:<br><br>";
echo 
$IP_ADDRESS;
?>
 
//It works up to here
 
<?php
system
("/usr/bin/bash <full path of script>/cnamegenerate.sh '$IP_ADDRESS'");
?>
Also make sure that the WebServer User (generally apache or any other) should have execute permission on the above shell script.
This User Gave Thanks to knight_eon For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Passing dynamic variable within another variable.

I have a small program which needs to pass variable dynamically to form the name of a second variable whose value wil be passed on to a third variable. ***************** Program Start ****************** LOC1=/loc1 PAT1IN=/loc2 PAT2IN=/loc3 if ; then for fpattern in `cat... (5 Replies)
Discussion started by: Cyril Jos
5 Replies

3. Shell Programming and Scripting

Passing variable with *

Hi Folks, I would like to pass a variable with a wild card in an argument. My script works if I don't use a wildcard but fails when I use *. I want to use the script like: scriptname -F <filename*> @ i = 0 while ($i <= ${#argv}) switch ($argv) case -F: set j = `echo $i +1... (2 Replies)
Discussion started by: dixits
2 Replies

4. Shell Programming and Scripting

help passing variable from script

Hello, How can I pass a variable into a 2nd file? I'm running a script: ls -la $1 >pem99 cat pem99 | awk '{ print $3}' >us99 cat us99 | read us98 This then tells me the owner of a file. my second file is: echo OWNER GROUP OTHERS echo echo --data-- $us98 ... (2 Replies)
Discussion started by: Grueben
2 Replies

5. Shell Programming and Scripting

piping ls to zenity and returning selection to variable

Hi I'm fairly new to unix and scripting (in BASH) and am here to post my first question. What I'm trying to do is pipe a sorted listing (ls) to zenity and when the list appears to the user, the choice they choose is returned to a variable so it can be used in conditional statements. I can... (2 Replies)
Discussion started by: Vayshan
2 Replies

6. UNIX for Dummies Questions & Answers

Loop on array variable returning error: 0 not found

I'm guessing i have a syntax error. I'm not sure it get's past the the while condition. I get an error 0 not found. Simple loop not sure what I'm doing wrong. #!/usr/bin/ksh set -A MtPtArray /u03 /u06 tUbound=${#MtPtArray } echo $tUbound i=0 while ($i -lt $tUbound) do print... (4 Replies)
Discussion started by: KME
4 Replies

7. Shell Programming and Scripting

passing a variable inside another variable.

Any help would be great. I know this is a dumb way of doing this, but I would like to know if there is a solution doing it this way. I'm very new at this and I'd like to learn more. Thanks! :D:D count=0 while ; do echo "enter your name" read name_$count let count=count+1 done ... (2 Replies)
Discussion started by: reconflux
2 Replies

8. UNIX for Dummies Questions & Answers

passing a variable inside a variable to a function

I would like to know how to pass a variable inside a variable to a function. sample code below -------------- for x in 1 9 do check_null $C$x ##call function to check if the value is null if then echo "line number:$var_cnt,... (2 Replies)
Discussion started by: KingVikram
2 Replies

9. UNIX for Dummies Questions & Answers

Variable passing

Hi, If a script A(Parent) is running and script B(child) is run from script A, will the variables in script A be past to script B? Will the variables exist only for the duration of running the script? Thank you (2 Replies)
Discussion started by: whugo
2 Replies

10. Programming

Passing C Variable To Unix

I want to pass a variable set in my c program to a shell script (which will also be invoked or initiated from the same C program using the C's system command). Is it possible ? :confused: (3 Replies)
Discussion started by: kapilv
3 Replies
Login or Register to Ask a Question