added catch fo rmissing logfile
This commit is contained in:
parent
adf0fecbdb
commit
868ff8831f
1 changed files with 18 additions and 14 deletions
32
functions
32
functions
|
|
@ -2,7 +2,7 @@
|
||||||
# pyr0ball script functions library
|
# pyr0ball script functions library
|
||||||
|
|
||||||
# Initial Vars
|
# Initial Vars
|
||||||
functionsrev=1.1.12
|
functionsrev=1.1.13
|
||||||
#scriptname="${BASH_SOURCE[0]##*/}"
|
#scriptname="${BASH_SOURCE[0]##*/}"
|
||||||
#rundir="${BASH_SOURCE[0]%/*}"
|
#rundir="${BASH_SOURCE[0]%/*}"
|
||||||
#rundir_absolute=$(cd $rundir && pwd)
|
#rundir_absolute=$(cd $rundir && pwd)
|
||||||
|
|
@ -411,19 +411,6 @@ popdfail(){
|
||||||
fail "$@"
|
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(){
|
run(){
|
||||||
_cmd=$@
|
_cmd=$@
|
||||||
if [[ $dry_run != true ]] ; then
|
if [[ $dry_run != true ]] ; then
|
||||||
|
|
@ -442,6 +429,23 @@ run-and-log(){
|
||||||
fi
|
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(){
|
ctrl_c(){
|
||||||
echo -e "\n"
|
echo -e "\n"
|
||||||
fail "User interrupted with Ctrl-C"
|
fail "User interrupted with Ctrl-C"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue