Skip to content
Snippets Groups Projects
Commit ad9a6494 authored by Jonathon Duerig's avatar Jonathon Duerig
Browse files

Added timetest.pl as an example for using hooks.

parent b0178846
No related branches found
No related tags found
No related merge requests found
set ns [new Simulator]
source tb_compat.tcl
set NodeA [$ns node]
tb-set-node-os $NodeA FEDORA10-STD
tb-add-node-service-hook "rc.isup" -script "/proj/tbres/duerig/timetest.pl" -op boot -whence every -env boot -point post -fatal 0
# Go!
$ns run
#!/usr/bin/perl
use strict;
use warnings;
my $debug = 0;
if (@ARGV >= 1 && $ARGV[0] eq '-d') {
$debug = 1;
shift @ARGV;
}
#die "Usage: $0 -d TOLERANCE boot\n" unless @ARGV == 1;
my $TOLERANCE = 0.5;
if (scalar(@ARGV) > 1) {
$TOLERANCE = $ARGV[0];
}
my $NTP_SERVER = "ops.emulab.net";
my $offset;
my $output = '';
open NTP, "/usr/sbin/ntpdate -q ops.emulab.net | ";
while (<NTP>) {
$output .= $_;
next unless /.+?: [a-z]+ time server .+? offset ([-+.\d]+) sec/;
$offset = $1;
}
unless (defined $offset) {
print STDERR "*** ERROR: Unable to get offset from ntpdata\n";
print STDERR "NOTE: ntpdate output\n";
print STDERR $output;
exit 2;
}
if (abs($offset) > $TOLERANCE) {
print STDERR "*** ERROR: offset of $offset greater than $TOLERANCE\n";
print "FAILED: offset of $offset greater than $TOLERANCE\n";
exit 1;
} else {
print "PASSED: offset of $offset within tolerance of $TOLERANCE\n";
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment