blob: ba53e05adbbb7547a95eab647c5c261350a4f602 (
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#! /usr/bin/perl -w
# 980904 Harlan Stenn - created
# vvv CHANGE THESE vvv
$ps = "/bin/ps x |";
$ntp_conf = "/etc/ntp.conf";
$ntpd = "/usr/local/bin/xntpd";
$ntpdate = "/usr/local/bin/ntpdate -b -s 10.0.0.1 10.0.0.2";
# ^^^ CHANGE THESE ^^^
{
if (0)
{
}
elsif ($ARGV[0] eq "start")
{
@pidlist = pidlist($ntpd);
if (defined(@pidlist))
{
warn "NTP is already running\n";
}
else
{
if ( -f $ntp_conf && -x $ntpd )
{
system ($ntpdate);
system ($ntpd." -c ".$ntp_conf);
}
}
}
elsif ($ARGV[0] eq "stop")
{
@pidlist = pidlist($ntpd);
kill 'TERM', @pidlist if (scalar(@pidlist) > 0);
}
else
{
die "Usage: $0 {start,stop}\n";
}
}
sub pidlist ($)
{
my ($target) = @_;
my ($qt) = quotemeta($target);
my @pids;
open(PS, $ps) || die "Can't run ps: $!\n";
while (<PS>)
{
chomp;
next unless (/$qt/);
print "Got <$_>\n";
if (/^\s*(\d+)\s+/)
{
push @pids, $1;
}
}
close(PS);
return @pids;
}
|