From: R. Steve McKown Date: Tue, 26 Nov 2013 16:59:22 +0000 (-0700) Subject: BackupPC_ovz: implment a ping command X-Git-Url: https://oss.titaniummirror.com/gitweb?p=ovzbpc.git;a=commitdiff_plain;h=1ece22d07b2f01e104f1060d26f153084f730e4a BackupPC_ovz: implment a ping command BackupPC entries for VEs can use this as their PingCmd: /usr/bin/BackupPC_ovz ping $host $pingPath -c 1 $host The Backup_PC_ovz script will run the command which is the text starting with the token '$pingPath', substituting '$host' for its HN if '$host' is found to be a VE. --- diff --git a/BackupPC_ovz b/BackupPC_ovz index 9e92313..bc7228d 100755 --- a/BackupPC_ovz +++ b/BackupPC_ovz @@ -435,6 +435,31 @@ sub checkRunningClient() } } +sub runPing() +{ + # This command generates ping output by pinging the host specified in the + # ping command still within @ARGV. However, if the host listed therein is + # a VE, the HN must be pinged instead. + + # Get the host + my $host = shift(@ARGV); + my $cmd = join(' ', @ARGV); + + # Find $host in the list of VEs + loadVeList(); + my $hostname = gethostbyaddr(gethostbyname($host), AF_INET); + mydie "Host $host not found" if (!defined($hostname)); + my $ve = getVeEntry('hostname', $hostname); + if (defined($ve)) { + $hostname = $ve->{'HN'}; + mydie "HN is undefined for host $host" if (!defined($hostname)); + $cmd =~ s/$host/$hostname/g; + print $dbgf ": ping request for $host remapped to HN $hostname\n"; + } + + cmdExecOrEval($cmd); +} + sub runClient($) { my ($restore) = @_; @@ -557,10 +582,21 @@ if ($ARGV[0] eq "restore") { #print "Restore mode\n"; } +my $ping = 0; +if ($ARGV[0] eq "ping") { + shift(@ARGV); + $ping = 1; + #print "Ping mode\n"; +} + +print $dbgf ": server=$server, refresh=$refresh, restore=$restore ping=$ping"; +print $dbgf " on ".`date`; if ($server) { runServer($restore); } elsif ($refresh) { refreshConfig(); +} elsif ($ping) { + runPing(); } else { runClient($restore); }