teetime: Initial version.

This commit is contained in:
Ole Tange 2020-07-22 02:33:55 +02:00
parent ef093d815d
commit 98907946d5
3 changed files with 236 additions and 18 deletions

View file

@ -2,9 +2,9 @@ CMD = blink 2grep 2search burncpu drac duplicate-packets em encdir \
field forever fxkill G gitnext gitundo goodpasswd histogram \
mtrr mirrorpdf neno off parsort pdfman pidcmd pidtree \
plotpipe puniq ramusage rand rclean rina rn rrm seekmaniac \
shython sound-reload splitvideo stdout swapout T timestamp \
tracefile transpose upsidedown vid w4it-for-port-open \
whitehash wifi-reload wssh ytv yyyymmdd
shython sound-reload splitvideo stdout swapout T teetime \
timestamp tracefile transpose upsidedown vid \
w4it-for-port-open whitehash wifi-reload wssh ytv yyyymmdd
all: blink/blink.1 2search/2grep.1 2search/2search.1 \
burncpu/burncpu.1 drac/drac.1 encdir/encdir.1 field/field.1 \
@ -15,10 +15,10 @@ all: blink/blink.1 2search/2grep.1 2search/2search.1 \
plotpipe/plotpipe.1 puniq/puniq.1 rand/rand.1 rina/rina.1 \
rn/rn.1 rrm/rrm.1 seekmaniac/seekmaniac.1 shython/shython.1 \
sound-reload/sound-reload.1 splitvideo/splitvideo.1 \
stdout/stdout.1 timestamp/timestamp.1 tracefile/tracefile.1 \
transpose/transpose.1 T/T.1 upsidedown/upsidedown.1 vid/vid.1 \
wifi-reload/wifi-reload.1 wssh/wssh.1 ytv/ytv.1 \
yyyymmdd/yyyymmdd.1
stdout/stdout.1 teetime/teetime.1 timestamp/timestamp.1 \
tracefile/tracefile.1 transpose/transpose.1 T/T.1 \
upsidedown/upsidedown.1 vid/vid.1 wifi-reload/wifi-reload.1 \
wssh/wssh.1 ytv/ytv.1 yyyymmdd/yyyymmdd.1
%.1: %
pod2man $< > $@

View file

@ -9,14 +9,15 @@ drac - Connect to iDRAC6 virtual console
=head1 SYNOPSIS
B<pdfman> I<manentry>
B<drac> [[I<user>[:I<password>]@]I<host>]
=head1 DESCRIPTION
B<drac> downloads the .jar file from the iDRAC6 and runs it with Java.
iDRAC6 uses a Java program to show the virtual console.
From the iDRAC6 B<drac> downloads the .jar file that is used to
connect to the iDRAC6's virtual console. Then it runs it with Java.
=head1 OPTIONS
@ -34,7 +35,7 @@ I<user> defaults to $DRAC_USER, which defaults to 'root'.
=item I<passwd>
I<passwd> defaults to $DRAC_PASSWD, which defaults to calvin.
I<passwd> defaults to $DRAC_PASSWD, which defaults to 'calvin'.
=back
@ -84,14 +85,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
=head1 DEPENDENCIES
B<pdfman> uses B<man> and B<ps2pdf>.
B<drac> uses B<java>.
=head1 SEE ALSO
B<java>
'
=cut
read host user passwd < <(echo "$1" |
@ -124,9 +125,11 @@ get=$(
)
$get http://"$DRAC_HOST"/software/avctKVM.jar > "$tmp"
(sleep 3; rm "$tmp") &
java -cp "$tmp" com.avocent.idrac.kvm.Main \
user="$DRAC_USER" passwd="$DRAC_PASSWD" ip="$DRAC_HOST" \
kmport=5900 vport=5900 apcp=1 version=2 vmprivilege=true \
"helpurl=https://$DRAC_HOST:443/help/contents.html"
(
rm "$tmp"
java -cp /dev/stdin com.avocent.idrac.kvm.Main \
user="$DRAC_USER" passwd="$DRAC_PASSWD" ip="$DRAC_HOST" \
kmport=5900 vport=5900 apcp=1 version=2 vmprivilege=true \
"helpurl=https://$DRAC_HOST:443/help/contents.html"
) < "$tmp"

215
teetime/teetime Executable file
View file

@ -0,0 +1,215 @@
#!/usr/bin/perl
=pod
=head1 NAME
teetime - Save stdin including timing
=head1 SYNOPSIS
... | teetime [-a] I<file> | ...
teetime -i I<file>
=head1 DESCRIPTION
B<teetime> saves stdin (standard input) to a file just like B<tee>.
Unlike B<tee> B<teetime> also timestamps input so it can be played
back with the same pauses.
=head1 OPTIONS
=over 4
=item B<--input>
=item B<-i>
Read I<file> as input.
=item B<--append>
=item B<-a>
Instead of overwriting I<file>, append to I<file>.
=back
=head1 EXAMPLES
(sleep 0.5; echo After 0.5s; sleep 1.5; echo After 2s) | teetime myfile
(sleep 0.5; echo After 2.5s; sleep 1.5; echo After 4s) | teetime -a myfile
teetime -i myfile
=head1 AUTHOR
Copyright (C) 2020 Ole Tange,
http://ole.tange.dk and Free Software Foundation, Inc.
=head1 LICENSE
Copyright (C) 2012 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
=head1 DEPENDENCIES
B<teetime> uses B<perl>.
=head1 SEE ALSO
B<tee>
=cut
use Getopt::Long;
sub now {
# Returns time since epoch as in seconds with 3 decimals
# Uses:
# @Global::use
# Returns:
# $time = time now with millisecond accuracy
if(not $Global::use{"Time::HiRes"}) {
if(eval "use Time::HiRes qw ( time );") {
eval "sub TimeHiRestime { return Time::HiRes::time };";
} else {
eval "sub TimeHiRestime { return time() };";
}
$Global::use{"Time::HiRes"} = 1;
}
return TimeHiRestime()*1000;
}
sub readstdin {
my $file = shift;
my $last_time = now();
my $rin = '';
my $in;
my $twogb = 2**31;
open(my $fh, ($opt::append ? ">>" : ">"), $file) || die;
#open(my $fh, ">", $file) || die;
vec($rin, fileno(STDIN), 1) = 1;
while(1) {
select($rin,undef,undef,undef);
if(sysread(STDIN,$in,$twogb)) {
my $time = now();
my $delta = $time - $last_time;
print $fh pack("L*",$delta,length $in),$in;
print STDOUT $in;
} else {
# Select says there is something to read,
# but there is not => eof
last;
}
}
close $fh;
}
sub readfile {
my $file = shift;
open(my $fh, "<", $file) || die;
while(1) {
my $in;
if(sysread($fh,$in,8)) {
($delta,$length) = unpack("L*",$in);
select(undef,undef,undef,$delta/1000);
sysread($fh,$in,$length);
print $in;
} else {
# Blocking sysread says there is something read,
# but there is not => eof
last;
}
}
}
sub version() {
# Returns: N/A
print join
("\n",
"GNU $Global::progname $Global::version",
"Copyright (C) 2020 Ole Tange, http://ole.tange.dk and Free Software",
"Foundation, Inc.",
"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>",
"This is free software: you are free to change and redistribute it.",
"GNU $Global::progname comes with no warranty.",
"",
"Web site: https://gitlab.com/ole.tange/tangetools/-/tree/master/${Global::progname}\n",
);
}
sub usage() {
# Returns: N/A
print join
("\n",
"Usage:",
"",
"... | teetime [-a] file | ...",
"teetime -i file",
"",
"-a append to file",
"-i read from file",
"",
"See 'man $Global::progname' for details",
"",);
}
sub help() {
# Returns: N/A
print join
("\n",
"GNU $Global::progname $Global::version",
"Copyright (C) 2020 Ole Tange, http://ole.tange.dk and Free Software",
"Foundation, Inc.",
"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>",
"This is free software: you are free to change and redistribute it.",
"GNU $Global::progname comes with no warranty.",
"",
"Web site: https://gitlab.com/ole.tange/tangetools/-/tree/master/${Global::progname}\n",
);
}
$|=1;
$Global::progname = "teetime";
$Global::version = "20200721";
if(GetOptions("debug|D=s" => \$opt::D,
"append|a" => \$opt::append,
"input|i" => \$opt::input,
"help|h" => \$opt::help,
"version|V" => \$opt::version)) {
if($opt::input) {
readfile(@ARGV);
} else {
readstdin(@ARGV);
}
} else {
help();
exit(1);
}