12 my $poll_frequency = 60;
14 # Send a command to switch and return the data recvied from the switch
16 my ($cmd, $conn) = @_;
18 # Send the command and get data from switch
19 my @data = $conn->cmd($cmd);
21 foreach my $line (@data) {
22 # Remove escape-7 sequence
23 $line =~ s/\x1b\x37//g;
30 sub switch_connect($) {
33 # Dump_Log => '/tmp/dumplog-queue',
34 my $conn = new Net::Telnet( Timeout => $timeout,
36 Prompt => '/(es3024|e\d+\-\dsw)>/i');
37 my $ret = $conn->open( Host => $ip);
38 if (!$ret || $ret != 1) {
41 # XXX: Just send the password as text, I did not figure out how to
42 # handle authentication with only password through $conn->login().
43 #$conn->login(»·Prompt => '/password[: ]*$/i',
45 # Password => $password);
46 $conn->cmd($nms::config::zyxel_password);
54 my $time = POSIX::ctime(time);
56 printf STDERR "[%s] %s\n", $time, $msg;
60 die("Error in arguments passed\n".
61 "./ssendfile.pl addr configfile\n");
64 my $conn = switch_connect($ARGV[0]);
65 if (!defined($conn)) {
66 die("Could not connect to switch.\n");
69 open(CONFIG, $ARGV[1]);
73 print "Executing: `$cmd`\n";
74 # if ($cmd =~ /ip ifconfig swif0 (\d{1-3}\.\d{1-3}\.\d{1-3}\.\d{1-3})/) {
75 # print "New ip: $1\n";
76 # $conn->cmd( String => $cmd,
78 # $conn = switch_connect($1);
79 # if (!defined($conn)) {
80 # die "Could not connect to new ip: $1\n";
84 my @data = switch_exec($cmd, $conn);
85 foreach my $line (@data) {
86 $line =~ s/[\r\n]+//g;