jbush82 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use Net::Ping; + # Module to check a remote host for reachability use Curses; + # Module to allow the use of system's curses $data_file="nms.systems2"; + # File which holds network node data open(DAT, $data_file) || die("COULD NOT OPEN SYSTEMS FILE: $!"); @raw_data=<DAT>; + # Array for holding node data close(DAT); $screen="/dev/tty9"; open(SAVEOUT, ">&STDOUT") || die("COULD NOT DUP STDOUT: $!"); open(STDOUT, ">", $screen) || die("COULD NOT REOPEN STDOUT ON $screen: + $!"); # Redirects standard output to $screen initscr(); + # Show header start_color(); init_pair(1, COLOR_CYAN, COLOR_BLACK); attron(COLOR_PAIR(1)); addstr(1, ($COLS -19) / 2, "Connectivity Status"); $y=0; + # Center line to split sides (comment out if not needed) while ($y != 20) { addstr(3+$y, 40, "|"); $y++; } attroff(COLOR_PAIR(1)); raw(); refresh(); foreach $system (@raw_data) { chop($system); ($ipaddr,$identity,$row,$col)=split(/\|/,$system); $p=Net::Ping->new("icmp"); if ($p->ping($ipaddr,1)) { start_color(); init_pair(2, COLOR_GREEN, COLOR_BLACK); + # If system is up, show output as green attron(COLOR_PAIR(2)); addstr($row, $col, "$identity"); + # Output information to specific location addstr($row+1, $col, " UP"); attroff(COLOR_PAIR(2)); } else { start_color(); init_pair(3, COLOR_RED, COLOR_BLACK); + # If system is down, show output as red attron(COLOR_PAIR(3)); addstr($row, $col, "$identity"); + # Output information to specific location addstr($row+1, $col, " DOWN"); attroff(COLOR_PAIR(3)); } refresh(); } endwin(); close(SAVEOUT); close(STDOUT);
127.0.0.1|gateway1|3|18 127.0.0.1|gateway2|3|54 127.0.0.1|system01|6|6 127.0.0.1|system02|6|18 127.0.0.1|system03|6|30 127.0.0.1|system11|6|42 127.0.0.1|system12|6|54 127.0.0.1|system13|6|66 127.0.0.1|system04|9|6 127.0.0.1|system05|9|18 127.0.0.1|system06|9|30 127.0.0.1|system14|9|42 127.0.0.1|system15|9|54 127.0.0.1|system16|9|66 127.0.0.1|system07|12|6 127.0.0.1|system08|12|18 127.0.0.1|system09|12|30 127.0.0.1|system17|12|42 127.0.0.1|system18|12|54 127.0.0.1|system19|12|66 127.0.0.1|system10|15|6 127.0.0.1|system20|15|42 127.0.0.1|system21|15|54 127.0.0.1|system22|15|66 127.0.0.1|system23|18|42 127.0.0.1|system24|18|54
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: output script to /dev/tty9
by Fletch (Bishop) on Dec 27, 2006 at 12:29 UTC | |
by jbush82 (Novice) on Dec 27, 2006 at 16:20 UTC | |
|
Re: output script to /dev/tty9
by jettero (Monsignor) on Dec 27, 2006 at 12:31 UTC | |
|
Re: output script to /dev/tty9
by Anonymous Monk on Dec 27, 2006 at 12:45 UTC | |
|
Re: output script to /dev/tty9
by jbush82 (Novice) on Dec 27, 2006 at 18:08 UTC |