]> git.sesse.net Git - nms/blob - web/ssendfile.pl
Merge.
[nms] / web / ssendfile.pl
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use lib '../include';
5 use POSIX;
6
7 my $delaytime = 30;
8 my $poll_frequency = 60;
9
10 sub mylog {
11         my $msg = shift;
12         my $time = POSIX::ctime(time);
13         $time =~ s/\n.*$//;
14         printf STDERR "[%s] %s\n", $time, $msg;
15 }
16
17 if ($#ARGV != 1) {
18         die("Error in arguments passed\n".
19                "./ssendfile.pl addr configfile\n");
20 }
21
22 my $conn = nms::switch_connect($ARGV[0]);
23 if (!defined($conn)) {
24         die("Could not connect to switch.\n");
25 }
26
27 open(CONFIG, $ARGV[1]);
28 while (<CONFIG>) {
29         my $cmd = $_;
30         $cmd =~ s/[\r\n]+//g;
31         print "Executing: `$cmd`\n";
32 #       if ($cmd =~ /ip ifconfig swif0 (\d{1-3}\.\d{1-3}\.\d{1-3}\.\d{1-3})/) {
33 #               print "New ip: $1\n";
34 #               $conn->cmd(     String => $cmd,
35 #                               Timeout => 3);
36 #               $conn = nms::switch_connect($1);
37 #               if (!defined($conn)) {
38 #                       die "Could not connect to new ip: $1\n";
39 #               }
40 #       }
41 #       else {
42                 my @data = nms::switch_exec($cmd, $conn);
43                 foreach my $line (@data) {
44                         $line =~ s/[\r\n]+//g;
45                         print "$line\n";
46                 }
47 #       }
48 }