Solved

Ping then post

Posted on 2002-07-17
7
216 Views
Last Modified: 2010-03-05
Hello,
I am totaly new to perl so please bear with me. What I am looking for is a way for my linux box to test/ping my connection at a set interval, and if it doesnt recieve a response to send a POST to my router that will tell it to reboot.

The code for the web page that launches the reboot is;
<FORM METHOD=POST ACTION="/reboot.html/set">
          <INPUT TYPE=submit NAME=reboot VALUE="Reboot">
          &nbsp;&nbsp;Are you sure? <INPUT TYPE=radio NAME=confirm VALUE=Yes >Yes
          <INPUT TYPE=radio NAME=confirm VALUE=No CHECKED>No
</FORM>

Any help will be much appreciated.
0
Comment
Question by:red_eye
  • 4
  • 3
7 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7160569
if your box does not respond to ping, how will you tell it to reboot? Has the router a dedicated connection (serial, or whatever) to the box?
0
 

Author Comment

by:red_eye
ID: 7160627
The Linux box and DSL router are on the same side of the connection e.g. they are both on my LAN. If the linux box tries to ping something on the internet and it fails then there is a good chance the router needs a reboot.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7160690
you still did not answer my question ...

Anyway, here as I would do it:

<FORM METHOD=POST ACTION="/ping.cgi">
 <INPUT TYPE=text   NAME=ip   VALUE="">
 <INPUT TYPE=submit NAME=ping VALUE="Ping">
</FORM>

when ping.cgi is called, it pings the given IP and returns a OK page:

<H2>Ping "ip" successful</H2>

or another form if the ping failed:

<FORM METHOD=POST ACTION="/reboot.cgi">
  <INPUT TYPE=submit NAME=reboot VALUE="Reboot">
  Are you sure?
  <INPUT TYPE=radio NAME=confirm VALUE=Yes >Yes
  <INPUT TYPE=radio NAME=confirm VALUE=No CHECKED>No
</FORM>

when reboot.cgi is called, it reboots what ever you want by issiung the approriate command.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:red_eye
ID: 7160722
Sorry I'm not making myself clear. The router, an efficient SpeedStream 5660 has a web interface. From the web interface it can be rebooted. It is connected via ethernet to a D-Link etherswitch. The Linux box is also connected to the etherswitch. So when my WAN/Internet connection is down the Router and Linux box are still connected on my LAN via ethernet. I want a script written in perl to run on the linux box, it should ping the internet and if there is no response to the pin then it should execute the Post method using the following data;

<FORM METHOD=POST ACTION="/reboot.html/set">
         <INPUT TYPE=submit NAME=reboot VALUE="Reboot">
         Are you sure? <INPUT TYPE=radio NAME=confirm VALUE=Yes >Yes
         </FORM>

In other words I want my Linux box when it doesnt find the connection to be up to push the peboot button on my router. A sample of the page I see in my router that I can reboot it from is at;
http://www.pcsites.com/sample/reboot.html

When I access my router via its intergrated web interface if I choose yes on that screen and click on the reboot button the router does a warm reboot.
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 100 total points
ID: 7160761
# push the reboot button:
wget 'http://your-router/reboot.html/set?confirm=Yes&reboot=Reboot'

If you wan to check the response of the router, see man wget, probably the -O option
0
 

Author Comment

by:red_eye
ID: 7160776
That worked perfectly now all I need to do is script the rest. Thanks.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7160801
good luck.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl script not writing to .csv file 6 111
use google analytics code in perl script 2 82
Formatting stings with pack and printf in perl 5 78
perl getopt long help 34 72
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

830 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