3 #=======================================================================
5 # File ID: ba10e77e-f743-11dd-adac-000475e441b9
6 # Creates ping(8) statistics for crappy connections.
9 # ©opyleft 2005– Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later, see end of
11 # file for legal stuff.
12 #=======================================================================
34 $progname =~ s/^.*\/(.*?)$/$1/;
35 our $VERSION = "0.00";
37 Getopt
::Long
::Configure
("bundling");
40 "debug" => \
$Opt{'debug'},
41 "help|h" => \
$Opt{'help'},
42 "verbose|v+" => \
$Opt{'verbose'},
43 "version" => \
$Opt{'version'},
45 ) || die("$progname: Option error. Use -h for help.\n");
47 $Opt{'debug'} && ($Debug = 1);
48 $Opt{'help'} && usage
(0);
49 if ($Opt{'version'}) {
54 my $Host = "194.248.216.19";
55 my $log_dir = "$ENV{HOME}/log/pingstat";
56 my $log_file = "$log_dir/pingstat.log";
57 my $lock_dir = "/var/lock/pingstat.LOCK";
58 my $CMD_PING = "/bin/ping -c 1 $Host";
61 (-d
$log_dir) || mkpath
($log_dir) || die("$progname: $log_dir: Cannot create directory: $!\n");
65 mkdir($lock_dir) || die("$lock_dir: Lockdir already exists.\n");
69 my ($Sec, $Min, $Hour, $Day, $Mon, $Year, $Wday, $Yday, $is_dst) =
71 my $Date = sprintf("%04u-%02u-%02uT%02u:%02u:%02uZ",
72 $Year + 1900, $Mon + 1, $Day, $Hour, $Min, $Sec);
73 $Year += 1900; # Weird piece of shit
75 if (open(PipeFP
, "$CMD_PING |")) {
76 my $Data = join("", <PipeFP
>);
79 if (open(LogFP
, ">>", $log_file)) {
80 if (flock(LogFP
, LOCK_EX
)) {
81 print(LogFP
"$Date\t$Data\n");
84 warn("$progname: $log_file: Cannot lock file: $!\n");
87 warn("$progname: $log_file: Cannot create or append to file: $!\n");
90 warn("$progname: \"$CMD_PING\": Could not open pipe: $!\n");
92 while (time < ($curr_time + $Delay)) {
98 # Print program version {{{
99 print("$progname v$VERSION\n");
104 # Send the help message to stdout {{{
107 if ($Opt{'verbose'}) {
113 Usage: $progname [options] [file [files [...]]]
120 Increase level of verbosity. Can be repeated.
122 Print version information.
124 Print debugging messages.
132 # Print a status message to stderr based on verbosity level {{{
133 my ($verbose_level, $Txt) = @_;
135 if ($Opt{'verbose'} >= $verbose_level) {
136 print(STDERR
"$progname: $Txt\n");
142 # Print a debugging message {{{
144 my @call_info = caller;
145 chomp(my $Txt = shift);
146 my $File = $call_info[1];
148 $File =~ s
#^.*/(.*?)$#$1#;
149 print(STDERR
"$File:$call_info[2] $$ $Txt\n");
156 # Plain Old Documentation (POD) {{{
166 [options] [file [files [...]]]
176 =item B<-h>, B<--help>
178 Print a brief help summary.
180 =item B<-v>, B<--verbose>
182 Increase level of verbosity. Can be repeated.
186 Print version information.
190 Print debugging messages.
200 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
204 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
205 This is free software; see the file F<COPYING> for legalese stuff.
209 This program is free software: you can redistribute it and/or modify it
210 under the terms of the GNU General Public License as published by the
211 Free Software Foundation, either version 2 of the License, or (at your
212 option) any later version.
214 This program is distributed in the hope that it will be useful, but
215 WITHOUT ANY WARRANTY; without even the implied warranty of
216 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
217 See the GNU General Public License for more details.
219 You should have received a copy of the GNU General Public License along
221 If not, see L<http://www.gnu.org/licenses/>.
229 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :