|
|
|||||||||
|
|
|
|
|
||||||
|
|
|
|
|
||||||
|
|
|
|
|
||||||
|
|
|||||||||
|
|
|||||||||
|
|
|
|
|
|
|
|
|
|
|
|
Links Back to the How-To List |
Create a CGI script using only shell scripting Problem: We needed a simple CGI interface to retrieve some information from the router (namely: the router's uptime, version, and our external (internet) IP address. Solution: A simple shell script, placed in Freesco's CGI script directory. Login to your Freesco box as root (via telnet). If you're using Freesco v0.2.7, type:
If you're using Freesco v0.3.0, type:
Now, copy the following, exactly as shown, into the editor (or download it here).
If possible, copy and paste it; even a single incorrect character could prevent the script from working.
#!/bin/sh
Some of the lines above have been wordwrapped; they must not be wrapped when you save them. If you've hand-typed this, and it's not working, pay particular attention to the characters following the "sed" commands. Also, make sure that there are exactly TWO blank lines between Content-type: text/plain and the line with
the exclamation point.Press Alt+X to exit, and press Y to save when prompted.Next, you need to make the script accessible to the webserver. Type:
Now, fire up a web browser, and open the following webpage:
Replace your_router with the IP or hostname of your router, and 85 with the
port your webserver is running on. You can replace uptime with any of
the following commands:ipaddr - Returns your current external (Internet) IP addressversion - Returns the current Linux kernel version (should always be 2.0.38)uptime - Returns the router's current uptimenetinfo - Returns information about your gateway/DNSsummary - Returns all of the aboveprobes - If you've setup our probe detect script, this displays any recent probesIf you add &raw=1 to the end of the URL, the script will just give you the
raw numbers. This is useful if you want to call this from an automated script on another server (as we do).
|
|