Solved

Execute a shell script from an html link - Passing varables back and forth?

Posted on 2010-11-16
15
416 Views
Last Modified: 2013-12-25
Still need some help this this:

Think I am missing something fundamental here; the submit button works even without entering in the name.

Also how do I pass the name to myscript.sh ???
One other option I would like to log with the name is the Users IP address to be passed to myscript.sh.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<div style="margin: 10px;">

<h2 class='specialT'> To restart environment </h2><div class='display'>
<h2 class='specialT'>Please Enter your name:</h2><div class='display'>

</p>
<form name="input" action="/cgi-bin/myscript.sh" method="get">
<input type="hidden" name="MANDATORY" value="UserName">
<pre>
          <input type="text" name="UserName"> <input type="submit" value="Submit" />
</pre>
</form>
<p>
0
Comment
Question by:hdaz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 5
15 Comments
 
LVL 16

Expert Comment

by:jmatix
ID: 34146538
1. To make the UserName mandatory add an onsubmit handler to your form as:

<form name="input" action="/cgi-bin/myscript.sh" method="get" onsubmit="ret = this.UserName.replace(/^\s+/, '') != ''; if (!ret) alert('Name is mandatory'); return ret;">

If you want to

2. UserName will be automatically passed to user shell script when you submit. You shell script can access it in environment variable named $QUERY_STRING.

3. User's hostname and IP address will be available in environment variables $REMOTE_HOST and $REMOTE_ADDR respectively.
0
 
LVL 1

Author Comment

by:hdaz
ID: 34147768
So doing the following in myscript.sh

echo "$QUERY_STRING $REMOTE_HOST $REMOTE_ADDR"

should give me the UserName and Remote host and Remote address but nothing is shown???
0
 
LVL 1

Author Comment

by:hdaz
ID: 34147808
I thought $QUERY_STRING was just for php?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:jmatix
ID: 34148097
QUERY_STRING is a CGI env variable set by the web server. Did you print an HTTP header? Try this:

echo -e "Content-type: text/html\n\n"
echo "<html><head></head><body>"

echo $QUERY_STRING
echo $REMOTE_ADDR

echo "</body></html>"

exit 0
0
 
LVL 1

Author Comment

by:hdaz
ID: 34148453
I added the following:

<form name="input" action="/cgi-bin/myscript.sh" method="get" onsubmit="ret = this.UserName.replace(/^\s+/, '') != ''; if (!ret) alert('Name is mandatory'); return ret;">

I saw it working and was happy not touched anything as far as I know and its stopped working

hmmm
0
 
LVL 1

Author Comment

by:hdaz
ID: 34148499
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<div style="margin: 10px;">

<h2 class='specialT'> To restart environment </h2><div class='display'>
<h2 class='specialT'>Please Enter your name:</h2><div class='display'>

</p>


<form name="input" action="/cgi-bin/myscript.sh" method="get" onsubmit="ret = this.UserName.replace(/^\s+/, '') != ''; if (!ret) alert('Name is mandatory'); return ret;">
<input type="hidden" name="MANDATORY" value="UserName">
<pre>
          <input type="text" name="UserName"> <input type="submit" value="Submit" />
</pre>
</form>
<p>
0
 
LVL 16

Expert Comment

by:jmatix
ID: 34148527
Not sure why it stopped working. Put it in a separate JS function as:

<form name="input" action="/cgi-bin/myscript.sh" method="get" onsubmit="return checkData(this);">


Then define  checkData() in your <script> block in <head> section as:

<script>
function checkData(frm)
{
   var ret = frm.UserName.replace(/^\s+/, '') != '';
   if (!ret)
        alert('Name is mandatory');
   return ret;
}
</script>
0
 
LVL 1

Author Comment

by:hdaz
ID: 34148792
Iv tried but nothing displays

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">

<div style="margin: 10px;">

<h2 class='specialT'> To restart environment </h2><div class='display'>
<h2 class='specialT'>Please Enter your name:</h2><div class='display'>

</p>

<form name="input" action="/cgi-bin/myscript.sh" method="get" onsubmit="return checkData(this);">

<input type="hidden" name="MANDATORY" value="UserName">
<pre>
          <input type="text" name="UserName"> <input type="submit" value="Submit" />
</pre>
</form>
<p>


<script>
function checkData(frm)
{
   var ret = frm.UserName.replace(/^\s+/, '') != '';
   if (!ret)
        alert('Name is mandatory');
   return ret;
}
</script>
0
 
LVL 16

Expert Comment

by:jmatix
ID: 34149024
My bad. Forgot to say frm.UserName.value. Try this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
function checkData(frm)
{
   var ret = frm.UserName.value.replace(/^\s+/, '') != '';
   if (!ret)
        alert('Name is mandatory');
   return false;
}
</script>
</head>
<body>
<div style="margin: 10px;">

<h2 class='specialT'> To restart environment </h2><div class='display'>
<h2 class='specialT'>Please Enter your name:</h2><div class='display'>

<p>

<form name="input" action="/cgi-bin/myscript.sh" method="get" onsubmit="return checkData(this);">

<input type="hidden" name="MANDATORY" value="UserName">
<pre>
          <input type="text" name="UserName"> <input type="submit" value="Submit" />
</pre>
</form>
<p>

</body>
</html>

Open in new window

0
 
LVL 1

Author Comment

by:hdaz
ID: 34149197
Thanks just tried the above still pressing submit without entering name or any data allows the script to be run...

0
 
LVL 16

Accepted Solution

by:
jmatix earned 500 total points
ID: 34149324
I just realized that there is another problem. It should be:

   return ret;

I tested the following HTML and it works for me.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
function checkData(frm)
{
   var ret = frm.UserName.value.replace(/^\s+/, '') != '';
   if (!ret)
        alert('Name is mandatory');
   return ret;
}
</script>
</head>
<body>
<div style="margin: 10px;">

<h2 class='specialT'> To restart environment </h2><div class='display'>
<h2 class='specialT'>Please Enter your name:</h2><div class='display'>

<p>

<form name="input" action="/cgi-bin/myscript.sh" method="get" onsubmit="return checkData(this);">

<input type="hidden" name="MANDATORY" value="UserName">
<pre>
          <input type="text" name="UserName"> <input type="submit" value="Submit" />
</pre>
</form>
<p>

</body>
</html>

Open in new window

0
 
LVL 1

Author Comment

by:hdaz
ID: 34149443
Interesting what are you using to do your testing ?? as it still allowed me to use the submit button

I am using CentOS 5.5 and Apache httpd-2.2.3-31.el5.centos.4

At this moment in time I am using w3m to test, i'll recheck again at but that wont be for a couple of days.
0
 
LVL 1

Author Comment

by:hdaz
ID: 34155488
I have tested with IE Firefox and Chrome as browsers...
0
 
LVL 1

Author Comment

by:hdaz
ID: 34156631
Sorry jmatix: I must apologize, I was giving false information....

i was testing the wrong script..... :)

Many thanks for your help and time.

hdaz
0
 
LVL 1

Author Closing Comment

by:hdaz
ID: 34156652
Thanks for all the help and time and please except my apologize for any confusion yesterday was a really long day.
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HTML INPUT 6 39
Powershell- Registry HIVE 6 63
Best explanation of following code css 11 40
Ordering displaying data in a drop down 3 8
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question