aboutsummaryrefslogtreecommitdiffstats
path: root/examples/historical/clients/ssendfile.pl
blob: 224f4e280db4ed22fc6264116d25f6353168ccbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/perl
use warnings;
use strict;
use lib '../include';
use POSIX;

my $delaytime = 30;
my $poll_frequency = 60;

sub mylog {
	my $msg = shift;
	my $time = POSIX::ctime(time);
	$time =~ s/\n.*$//;
	printf STDERR "[%s] %s\n", $time, $msg;
}

if ($#ARGV != 1) {
	die("Error in arguments passed\n".
	       "./ssendfile.pl addr configfile\n");
}

my $ssh = nms::switch_connect_ssh($ARGV[0]);
my $conn = $ssh->{telnet};
if (!defined($conn)) {
	die("Could not connect to switch.\n");
}

open(CONFIG, $ARGV[1]);
while (<CONFIG>) {
	my $cmd = $_;
	$cmd =~ s/[\r\n]+//g;
	print "Executing: `$cmd`\n";
#	if ($cmd =~ /ip ifconfig swif0 (\d{1-3}\.\d{1-3}\.\d{1-3}\.\d{1-3})/) {
#		print "New ip: $1\n";
#		$conn->cmd(	String => $cmd,
#				Timeout => 3);
#		$ssh = nms::switch_connect_ssh($1);
#		$conn = $ssh->{telnet};
#		if (!defined($conn)) {
#			die "Could not connect to new ip: $1\n";
#		}
#	}
#	else {
		my @data = nms::switch_exec($cmd, $conn);
		foreach my $line (@data) {
			$line =~ s/[\r\n]+//g;
			print "$line\n";
		}
#	}
}