# teeshell
date=$(date +%Y-%m-%d_%H-%M-%S)
randstr=$(cat /dev/urandom | env LC_CTYPE=C tr -cd 'a-f0-9' | head -c 4)
dir="$(echo ~/log/"${date}_${randstr}")"
mkdir "$dir"
# Redirect everything to tee and perl
exec 1> >(tee /dev/tty |
perl -pe '
sub reopen {
open(OUT,">'$dir'/".++$i);
select OUT;
$| = 1;
}
BEGIN {
'echo $$ > "'$dir'"/pid';
reopen();
$SIG{HUP} = \&reopen;
}') 2>&1
# wait for perl to save the pid
while [ ! -f "$dir"/pid ] ; do
true
done
# Magic! Make perl save to a new file with a kill -HUP
PS1="[\$(kill -HUP 'cat "$dir"/pid')][\u@\h:\w]\$ "
Executar:
. teeshell