tracefile --help implemented.

This commit is contained in:
Ole Tange 2022-10-21 20:32:20 +02:00
parent 81ebcc00be
commit eeca10eda9
10 changed files with 128 additions and 41 deletions

View file

@ -17,7 +17,8 @@ disk for each. So if you have a USB drive in your physical key ring,
you can use the same drive for all the machines you boot when being
physically close.
You add the key with:
You add the key with (/dev/sda5 is the full-disk encrypted device you
want to unlock):
cryptsetup luksAddKey /dev/sda5
@ -45,8 +46,13 @@ your initramfs, you need to add them by adding to
sdhci
sdhci_pci
Copy the relevant cryptroot to
/usr/share/initramfs-tools/scripts/local-top/cryptroot
When all is done, update the initramfs:
update-initramfs -u
(C) 2014 Ole Tange, GPLv2 or later
Now reboot the system with the USB-disk connected.
(C) 2014-2022 Ole Tange, GPLv2 or later

View file

@ -114,7 +114,7 @@ else
DRAC_HOST="$host"
fi
tmp=$(tempfile)
tmp=$(mktemp)
# Find a command line tool to download with
get=$(

View file

@ -118,7 +118,7 @@ after HOME=.
Complex commands can also be run:
find-first-fail -v perl -e 'exit(shift > 129)'
find-first-fail -v perl -e 'exit(shift > 12345678)'
=head2 Find the second limit of a program
@ -152,6 +152,29 @@ To identify the minimal CSV file that causes myparser to fail:
find-first-fail -f example.csv -s1 myparser
=head2 Find minimal file fragment with two Rs
cat file.txt
11
22
R
33
44
55
R
66
77
R
88
myfunc() { perl -ne 'END{ exit($a>1) } $a += /R/' "$@"; }
find-first-fail -vf file.txt myfunc
This will find a fragment with only two Rs. If there are more (which
there is in this case), it may not find the smallest. It will,
however, minimize the one it finds.
=head1 REPORTING BUGS
@ -160,7 +183,7 @@ Report bugs: https://gitlab.com/ole.tange/tangetools/-/issues
=head1 AUTHOR
Copyright (C) 2020 Ole Tange,
Copyright (C) 2020-2022 Ole Tange,
http://ole.tange.dk and Free Software Foundation, Inc.
@ -294,7 +317,8 @@ find-first-fail() {
shift
shift
local cmd=("$@")
local tmp=`tempfile -p fff`
local ext=${inputfile##*.}
local tmp=$(mktemp fffXXXXX.$ext)
$verbose && echo "$a<x<$b: ${cmd[@]}" "$tmp" >&2
# Build file of line a..b
perl -ne "($start and 1..$start) and print" "$inputfile" > "$tmp";

View file

@ -3,7 +3,7 @@
test_unexported_function() {
myprog() { perl -e 'exit (shift > 12345678)' "$@"; }
# myprog is a function, so source find-first-fail first
. `which find-first-fail`
. "$(command -v find-first-fail)"
echo Find 12345678 in unexported function
find-first-fail myprog
}
@ -38,45 +38,44 @@ test_s_v_12() {
}
test_file() {
tmp=`tempfile`
echo Header > $tmp
seq 100 >> $tmp
echo 10 >> $tmp
echo 12 >> $tmp
echo 15 >> $tmp
10_to_15() { grep ^10$ $1 && grep ^15$ $1; }
tmp=$(mktemp)
(echo Header
seq 100
echo 10
echo 12
echo 15) > "$tmp"
10_to_15() { grep ^10$ "$1" && grep ^15$ "$1"; }
export -f 10_to_15
echo 10..15
find-first-fail -s1 -qf $tmp 10_to_15
find-first-fail -s1 -qf "$tmp" 10_to_15
echo not 10..15
find-first-fail -s1 -qf $tmp not 10_to_15
rm $tmp
find-first-fail -s1 -qf "$tmp" not 10_to_15
rm "$tmp"
}
test_header() {
tmp=`tempfile`
echo Header > $tmp
seq 10 >> $tmp
echo 1000 >> $tmp
seq 10 >> $tmp
tmp=$(mktemp)
(echo Header
seq 10
echo 1000
seq 10) > "$tmp"
myparser() { perl -ne 'if($_ > 100) { exit 1 }' "$@"; }
export -f myparser
echo Should give:
echo Header
echo 1000
find-first-fail -s1 -f $tmp myparser
find-first-fail -s1 -f "$tmp" myparser
}
test_file_start_middle_end() {
tmp=`tempfile`
tmp=$(mktemp)
testfile() {
(echo MyHeader
echo $1
echo "$1"
echo 2
echo $2
echo "$2"
echo 4
echo $3) > "$tmp"
echo "$3") > "$tmp"
}
myparser() { perl -ne 'if($_ > 10) { exit 1 }' "$@"; }
export -f myparser
@ -89,10 +88,10 @@ test_file_start_middle_end() {
echo 'Find 1005'
testfile 1 3 1005
find-first-fail -s1 -f "$tmp" myparser
echo 'Find 1001/1005'
echo 'Find 1001 or 1005'
testfile 1001 3 1005
find-first-fail -s1 -f "$tmp" myparser
echo 'Find 1001/1003/1005'
echo 'Find 1001 or 1003 or 1005'
testfile 1001 1003 1005
find-first-fail -s1 -f "$tmp" myparser
}
@ -105,6 +104,13 @@ test_end() {
find-first-fail -v -s 11 -e 15 myprog
}
test_dashdash() {
echo 'Test -- will allow a function named -q'
-q() { perl -e 'exit (shift > 12)' "$@"; }
export -f -- -q
find-first-fail -q -- -q
}
export -f $(compgen -A function | grep test_)
compgen -A function | grep test_ | LC_ALL=C sort |
parallel --timeout 1000% --tag -k --joblog /tmp/jl-`basename $0` '{} 2>&1'
parallel --timeout 1000% --tag -k --joblog /tmp/jl-"$(basename "$0")" '{} 2>&1'

View file

@ -50,7 +50,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
=head1 DEPENDENCIES
B<mirrorpdf> uses B<pdf2ps>, B<pstops>, B<pdftk>, and B<ps2pdf>.
B<mirrorpdf> uses B<pdf2ps>, B<pstops> (from psutils), B<pdftk>, and
B<ps2pdf>.
=head1 SEE ALSO
@ -66,10 +67,9 @@ mirror() {
# Flip both horizontally and vertically
pstops H |
ps2pdf - $tmp
# Flip both horizontally and vertically
# Rotate 180 deg
pdftk $tmp cat 1-endnorth output "$2"
rm $tmp
}
export -f mirror
parallel mirror {} {.}_mirror.pdf ::: "$@"

11
rrm/rrm
View file

@ -56,6 +56,14 @@ my %size;
my %hashval;
my @remove;
for my $file (@ARGV) {
if(not -e $file) {
warn("File does not exist: $file");
next;
}
if(not -f $file) {
warn("Not a file: $file");
next;
}
if(-s $file > 0) {
$size{$file} = -s $file;
my $sha = Digest::SHA->new(256);
@ -63,9 +71,6 @@ for my $file (@ARGV) {
$hashval{$file} = "SHA256:".$sha->b64digest;
push @remove, $file;
}
if(not -e $file) {
warn("File does not exist: $file");
}
}
$rrmfile = find_rrm_file(".") || ".rrm";

View file

@ -94,6 +94,13 @@ if(not -e $infile or $time !~ /\d\d:\d\d:\d\d.\d/) {
"To split video.file at HH:MM:SS.t\n",
"The original file will be moved to .../.rm\n\n";
} else {
# https://github.com/mifi/lossless-cut/pull/13
# '-noaccurate_seek',
# '-ss', cutFrom,
# '-i', filePath, '-y', '-vcodec', 'copy', '-acodec', 'copy',
# '-to', cutTo,
# '-f', format,
# '-avoid_negative_ts', 'make_zero',
my ($start_file,$end_file) = destinationfilenames($infile,$time);
# fmpeg -t 00:25:29 -i in.mp4 -c copy out-start.mp4
my @start = ("ffmpeg","-t",$time,"-i","file:$infile","-c","copy","file:$start_file");

View file

@ -6,9 +6,9 @@ tracefile - list files being accessed
=head1 SYNOPSIS
B<tracefile> [-adeflnruw] I<command>
B<tracefile> [-adefhlnruw] I<command>
B<tracefile> [-adeflnruw] -p I<pid>
B<tracefile> [-adefhlnruw] -p I<pid>
=head1 DESCRIPTION
@ -51,6 +51,13 @@ List only existing files.
List only normal files.
=item B<-h>
=item B<--help>
Show help text.
=item B<-l>
=item B<--local>
@ -246,12 +253,14 @@ B<strace>(1)
use Getopt::Long;
sub version();
sub help();
$Global::progname = "tracefile";
$Global::version = 20220701;
Getopt::Long::Configure("bundling","require_order");
get_options_from_array(\@ARGV) || die_usage();
if($opt::version) { version(); exit(0); }
if($opt::help) { help(); exit(0); }
init_functions();
my @cmd = shell_quote(@ARGV);
@ -429,6 +438,7 @@ sub options_hash {
"write|w" => \$opt::write,
"all|a" => \$opt::all,
"pid|p=i" => \$opt::pid,
"help|h" => \$opt::help,
);
}
@ -519,7 +529,7 @@ sub version() {
print join
("\n",
"$Global::progname $Global::version",
"Copyright (C) 2020 Ole Tange, http://ole.tange.dk and Free Software",
"Copyright (C) 2020-2022 Ole Tange, http://ole.tange.dk and Free Software",
"Foundation, Inc.",
"License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>",
"This is free software: you are free to change and redistribute it.",
@ -530,6 +540,26 @@ sub version() {
}
sub help() {
# Returns: N/A
print join
("\n",
"Usage:",
" $Global::progname [-adefhlnruw] (command|-p pid)",
" -a --all",
" -d --dir",
" -e --exist",
" -f --file",
" -h --help",
" -l --local",
" -n --nonexist",
" -r --read",
" -u --unique",
" -w --write",
""
);
}
sub my_dump(@) {
# Returns:
# ascii expression of object if Data::Dump(er) is installed

View file

@ -145,7 +145,7 @@ stdout() {
if [ -t 1 ] ; then
# STDOUT = terminal
# start VLC
parallel --lb -Xj1 vlc
parallel --halt now,done=1 --lb -Xj1 vlc
else
cat
fi

View file

@ -74,6 +74,15 @@ my $host = shift @ARGV;
$host =~ s/.*\@//;
print STDERR $host;
system("w4it-for-port-open $host 22");
# To avoid:
#
# "System is booting up. Unprivileged users are not permitted to log
# in yet. Please come back later. For technical details, see
# pam_nologin(8)."
#
# wait for 2 seconds
sleep(2);
exec @ARGV;
sub options_hash {