?
Solved

Script to execute external programs

Posted on 2000-02-17
8
Medium Priority
?
186 Views
Last Modified: 2013-12-25
I need some help writing a cgi script that allows a user to select (from check boxes) a list of programs to run and then run those progams (ping, traceroute, etc) and have the output on he same web page.

The page should have a list of check boxes and when they click submit the programs associated get execute. The output for each program should be on the bottom of the page (or even a little popup window)

Thanks
0
Comment
Question by:mdlittle
[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
  • 4
  • 4
8 Comments
 
LVL 16

Expert Comment

by:maneshr
ID: 2535174
try this................

currently i only have ping & traceroute, but you can add as many as you want.


====commands.pl
#!/usr/local/bin/perl

use CGI;

$query=new CGI;

print "Content-type: text/html\n\n";

print "
<form method=post action=\"".$ENV{SCRIPT_NAME}."\">
<TABLE BORDER=1>
<TD><input type=checkbox name=cb1 value=\"ping\">Ping</TD>
<TD><input type=text name=ping></TD>
<TR>
<TD><input type=checkbox name=cb1 value=\"traceroute\">Traceroute</TD>
<TD><input type=text name=traceroute></TD>
<TR>
<TD align=center colspan=2><input type=submit value=\"Show me!!\"></TD>
</TABLE>
</form>";

if ($query->param){
  print "<hr>\n";
  @cb=$query->param('cb1');
  $command{'ping'}=$query->param('ping');
  $command{'traceroute'}=$query->param('traceroute');
  $command{'ping'}=~ s/\s+/ /g; ##  Squeeze multiple space to one space
  $command{'traceroute'}=~ s/\s+/ /g; ##  Squeeze multiple space to one space

  if (scalar @cb == 0){
    print "<B>Select at least one item!!</B>\n";
    exit;
  }

  foreach $command (@cb){
    if ($command{$command}){  ## Param for that check box specified
      if ($command=~ /^ping$/){
        #$output="$command -c 3 $command{$command} 2> /dev/null";
        $output=`$command -c 3 $command{$command} 2> /dev/null`;
      }else{
        #$output="$command $command{$command} 2> /dev/null";
        $output=`$command $command{$command} 2> /dev/null`;
      }
      print "<B>",$command,"</B><BR>\n";
      print "<pre>",$output,"</pre><P>\n";
    }else{
      print "<B>You need to specify param for $command</B><BR>\n";
    }
  }
}
0
 

Author Comment

by:mdlittle
ID: 2535398
Adjusted points to 550
0
 

Author Comment

by:mdlittle
ID: 2535400
I know I did not ask for this... but is there a way to specifiy which traceroute and which ping program to use (in the script not on the web page) as configuration parameters. I want to do this because I may not use ping or traceroute - it may be other programs.

This is exactly what I wanted and if you could help with the above I will immediately award points. I increased it 50 points

Thanks
0
Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

 
LVL 16

Expert Comment

by:maneshr
ID: 2535585
as per your original question ".....programs to run and then run those progams (ping, traceroute, etc)...." you clearly want to run ping,  traceroute etc....

what do you want do do when you now  say "....but is there a way to specifiy which traceroute and which ping program to use ......" & "I want to do this because I may not use ping or traceroute - it may be other programs. "

do you mean you might want to run your own program, inside which you have ping and /or traceroute commands???

Pl. clarify. if possible provide some sample programs
0
 

Author Comment

by:mdlittle
ID: 2535718
I may want to run other programs other than ping and traceroute. It's pretty simple. You script works as I had requested I just wanted a little more clairification on how to add additional programs.

Mike
0
 
LVL 16

Accepted Solution

by:
maneshr earned 2200 total points
ID: 2535764
Ok....

this part of the PERL script print the HTML form(checkbox etc..)

print " 
<form method=post action=\"".$ENV{SCRIPT_NAME}."\">
<TABLE BORDER=1>
<TD><input type=checkbox name=cb1 value=\"ping\">Ping</TD>
<TD><input type=text name=ping></TD>
<TR>
<TD><input type=checkbox name=cb1 value=\"traceroute\">Traceroute</TD>
<TD><input type=text name=traceroute></TD>
<TR>
<TD align=center colspan=2><input type=submit value=\"Show me!!\"></TD>
</TABLE>
</form>";

Now lets say you want to add another program (which), here's how you do it..

1) add ...

<TD><input type=checkbox name=cb1 value=\"which\">Which</TD>
<TD><input type=text name=which></TD>
<TR>

NOTE: the value of the checkbox var is the same as the name of the textbox.

2) in the if statement add this....

if ($query->param){
print "<hr>\n";
@cb=$query->param('cb1');
$command{'ping'}=$query->param('ping');
$command{'traceroute'}=$query->param('traceroute');

$command{'which'}=$query->param('which');  ##Add this

$command{'ping'}=~ s/\s+/ /g; ##  Squeeze multiple space to one space
$command{'traceroute'}=~ s/\s+/ /g; ##  Squeeze multiple space to one space

$command{'which'}=~ s/\s+/ /g; ##   Add this


That's it!!

you are ready to go.

0
 

Author Comment

by:mdlittle
ID: 2535805
Awesome. Thanks for your help - again!
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2535821
most welcome!! :-)
0

Featured Post

TCP/IP Network Protocol Cheat Sheet

TCP/IP is a set of network protocols which is best known for connecting the machines that make up the Internet. The truth is that TCP/IP is one of the oldest network protocols and its survival is mainly based on its simplicity and universality.

Question has a verified solution.

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

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

771 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