Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-11-16
15
Medium Priority
?
426 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:Justin Mathews
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
Industry Leaders: 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:Justin Mathews
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:Justin Mathews
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:Justin Mathews
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:
Justin Mathews earned 2000 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

Not sure which OpenStack Certification to get?

So you’ve realized you might want to get certified in OpenStack, but you’re not sure what the benefits might be or even which one you should take. You know there are several certification courses you can choose from, but how do you know which one is right for you?

Question has a verified solution.

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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

718 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