added catch fo rmissing logfile

This commit is contained in:
pyr0ball 2023-05-08 16:45:51 -07:00
parent adf0fecbdb
commit 868ff8831f

View file

@ -2,7 +2,7 @@
# pyr0ball script functions library
# Initial Vars
functionsrev=1.1.12
functionsrev=1.1.13
#scriptname="${BASH_SOURCE[0]##*/}"
#rundir="${BASH_SOURCE[0]%/*}"
#rundir_absolute=$(cd $rundir && pwd)
@ -411,19 +411,6 @@ popdfail(){
fail "$@"
}
logger(){
$@ 2>&1 | tee >(
while IFS= read -r line; do
# strip any escaped strings for logging output
_line=$(echo $line | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | tr -dc '[:print:]')
# only print out non-empty lines to log
if [[ "$_line" != "" ]] ; then
printf '[%s] %s\n' "${scriptname}][${pretty_date}" "$_line"
fi
done >> $logfile
)
}
run(){
_cmd=$@
if [[ $dry_run != true ]] ; then
@ -442,6 +429,23 @@ run-and-log(){
fi
}
logger(){
if [ ! -f $logfile ] ; then
run mkdir -p ${rundir%/*}
touch $logfile
fi
$@ 2>&1 | tee >(
while IFS= read -r line; do
# strip any escaped strings for logging output
_line=$(echo $line | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | tr -dc '[:print:]')
# only print out non-empty lines to log
if [[ "$_line" != "" ]] ; then
printf '[%s] %s\n' "${scriptname}][${pretty_date}" "$_line"
fi
done >> $logfile
)
}
ctrl_c(){
echo -e "\n"
fail "User interrupted with Ctrl-C"