Sponsored Content
Top Forums Shell Programming and Scripting Launch shell script with parameters from a webpage button Post 302914867 by junior-helper on Thursday 28th of August 2014 12:53:52 PM
Old 08-28-2014
Bug

1. The actual reason why the output file test.txt is empty is because the URL contains some special symbols, such as "&", which breaks the issued command. This can be fixed with proper quoting:
Code:
$output = shell_exec("echo '$uri' > /tmp/test.txt");

2. The syntax looks good, apart from the mentioned quoting. The interpretor/hashbang/shebang is not needed. It's outside the php section and is treated as plain text, so you can remove it. Inside the php section it would be a comment.

3. You write you get a blank page, but what did you expect? Due to echo'ing a string and redirecting it to a file there is no output to be returned. Add this to your php script to see some output:
Code:
$output2 = shell_exec('ls -l /tmp/test.txt');
echo "<pre>$output2</pre>";

4. Breaking down the URL is not a good idea. Try to figure out why.

Complete demo incl. shell script for processing the form data:

html file: unchanged

php file (script.php):
PHP Code:
<?php
$field1 
$_GET["sdate"];
$field2 $_GET["edate"];
$field3 $_GET["adress"];
echo 
"$field1 $field2 $field3";
//Obviously, this is a temporary location :D
$output shell_exec("/tmp/process-fields.sh '$field1' '$field2' '$field3'");
echo 
"<pre>$output</pre>";
?>
shell script (process-fields.sh):
Code:
#!/bin/bash
echo "BASH FIELD 1:    $1"
echo "BASH FIELD 2:    $2"
echo "BASH FIELD 3:    $3"

output:
Code:
08/25/2014 08/28/2014 info@example.com

BASH FIELD 1:    08/25/2014
BASH FIELD 2:    08/28/2014
BASH FIELD 3:    info@example.com

All in all it's nice to play with and stuff, but from the security point of view it's a big disaster, imho.
Learn the difference between GET and POST method, implement some form validation etc etc
These 2 Users Gave Thanks to junior-helper For This Post:
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script for using the Back button and the Close button

Here's a question I have for anyone that might be able to help me: I can write a html script that will allow the user to return to the previous page using the back button, and I can write a script that will allow the user to return to the previous page using the close button, but...is there a... (1 Reply)
Discussion started by: mdgibson
1 Replies

2. Shell Programming and Scripting

How to launch a Csh shell script using Excel Macro ?

Hi all. I need to use excel macro at my desktop to launch a csh script which is in a solaris environment. What is the code that i can use in macro to help me with that ? Basically, the code need to telnet or ftp to the solaris environment and just run the script and the macro will output in an... (1 Reply)
Discussion started by: Raynon
1 Replies

3. Shell Programming and Scripting

BASH: how to launch a program with parameters

Hi, I'm a pretty big fan of BASH scripting. I've got a bunch I use for random things and lately a couple issues have been plaguing me. Both are somewhat related, in that they deal with filenames with spaces and "escaped" characters and with launching a program with command line arguements... (5 Replies)
Discussion started by: TinCanFury
5 Replies

4. Shell Programming and Scripting

Run shell commands via HTML webpage/button?

Hey guys, I got a issue here... we have a development box and a UAT box that our webmasters use, they do the webpage development on the development box and and save changed files to a particular directory on the dev machine. At a certain time of the day a cronjob kicks off and the... (3 Replies)
Discussion started by: zeekblack
3 Replies

5. Shell Programming and Scripting

launch vnc session from unix shell script

Hi All, OS:AIX 64 bits Would like to know what is the command to launch vnc session from unix shell script so that Reports server is started from vnc session which should be launched from within the shell script. Thanks for your time! Regards, (0 Replies)
Discussion started by: a1_win
0 Replies

6. Shell Programming and Scripting

Shell Script to launch C program

Hi there, im new too shell scripting and was wondering if it is possible to create a shell script to take in a variable and load a c program. My C program is a file monitor, and is started by using the terminal and using to following code ./monitor FileToBeMonitored is it possible to have... (12 Replies)
Discussion started by: gazmcc182
12 Replies

7. Shell Programming and Scripting

Help to create a Return Button using shell script CGI

Hello Guys, I would like to know how can I create a radio button on that its possible to return to the last page, using a ksh CGI shell script. Can someone help ? Thanks so much !!!:b: I tried this, but it is a javascript code ! <INPUT TYPE="button" VALUE="BACK" ... (2 Replies)
Discussion started by: robdcb
2 Replies

8. Shell Programming and Scripting

Read webpage from shell script

Hey experts, I am trying to read a webpage and want to search for a text patter (case insensitive). Please help me acquire this. If the text is found i will receive a mail which can be hardcoded in the script. I am not a big fan of using PERL script. Please help. Machine: AIX... (15 Replies)
Discussion started by: bankimmehta
15 Replies

9. Shell Programming and Scripting

Executing Shell Script from PHP Webpage

Hello , I am trying to execute a small shell script from a PHP Webpage. Below is the shell script : 1.sh $ cat /home/oracle/rahul/1.sh #!/bin/ksh echo "`date` : Report generation in progress" > /home/oracle/rahul/report.txt echo "Run successfully script"; Below is the PHP... (1 Reply)
Discussion started by: rahul2662
1 Replies
All times are GMT -4. The time now is 01:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy