From 98907946d55a7c72a5a0d02cb20f89099a88e6a9 Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Wed, 22 Jul 2020 02:33:55 +0200 Subject: [PATCH] teetime: Initial version. --- Makefile | 14 ++-- drac/drac | 25 +++--- teetime/teetime | 215 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 236 insertions(+), 18 deletions(-) create mode 100755 teetime/teetime diff --git a/Makefile b/Makefile index 06a7b79..33a94eb 100644 --- a/Makefile +++ b/Makefile @@ -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 $< > $@ diff --git a/drac/drac b/drac/drac index 313a44e..0f28689 100755 --- a/drac/drac +++ b/drac/drac @@ -9,14 +9,15 @@ drac - Connect to iDRAC6 virtual console =head1 SYNOPSIS -B I - B [[I[:I]@]I] =head1 DESCRIPTION -B 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 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 defaults to $DRAC_USER, which defaults to 'root'. =item I -I defaults to $DRAC_PASSWD, which defaults to calvin. +I defaults to $DRAC_PASSWD, which defaults to 'calvin'. =back @@ -84,14 +85,14 @@ along with this program. If not, see . =head1 DEPENDENCIES -B uses B and B. +B uses B. =head1 SEE ALSO B - +' =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" diff --git a/teetime/teetime b/teetime/teetime new file mode 100755 index 0000000..f89bcf4 --- /dev/null +++ b/teetime/teetime @@ -0,0 +1,215 @@ +#!/usr/bin/perl + +=pod + +=head1 NAME + +teetime - Save stdin including timing + + +=head1 SYNOPSIS + +... | teetime [-a] I | ... + +teetime -i I + + +=head1 DESCRIPTION + +B saves stdin (standard input) to a file just like B. + +Unlike B B 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 as input. + + +=item B<--append> + +=item B<-a> + +Instead of overwriting I, append to I. + + +=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 . + + +=head1 DEPENDENCIES + +B uses B. + + +=head1 SEE ALSO + +B + + +=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 ", + "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 ", + "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); +} + +