Fix for junk /osync.remote folder not being deleted
This commit is contained in:
parent
b0b91a4db0
commit
ca78d76bb2
|
@ -31,7 +31,7 @@
|
||||||
#### OFUNCTIONS MINI SUBSET ####
|
#### OFUNCTIONS MINI SUBSET ####
|
||||||
#### OFUNCTIONS MICRO SUBSET ####
|
#### OFUNCTIONS MICRO SUBSET ####
|
||||||
_OFUNCTIONS_VERSION=2.3.0-dev-postRC2
|
_OFUNCTIONS_VERSION=2.3.0-dev-postRC2
|
||||||
_OFUNCTIONS_BUILD=2019070501
|
_OFUNCTIONS_BUILD=2019070502
|
||||||
#### _OFUNCTIONS_BOOTSTRAP SUBSET ####
|
#### _OFUNCTIONS_BOOTSTRAP SUBSET ####
|
||||||
_OFUNCTIONS_BOOTSTRAP=true
|
_OFUNCTIONS_BOOTSTRAP=true
|
||||||
#### _OFUNCTIONS_BOOTSTRAP SUBSET END ####
|
#### _OFUNCTIONS_BOOTSTRAP SUBSET END ####
|
||||||
|
@ -84,8 +84,30 @@ if [ "$SLEEP_TIME" == "" ]; then # Leave the possibity to set SLEEP_TIME as envi
|
||||||
fi
|
fi
|
||||||
#### DEBUG SUBSET END ####
|
#### DEBUG SUBSET END ####
|
||||||
|
|
||||||
|
# The variables SCRIPT_PID and TSTAMP needs to be declared as soon as the program begins. The function PoorMansRandomGenerator is needed for TSTAMP (since some systems date function does not give nanoseconds)
|
||||||
|
|
||||||
SCRIPT_PID=$$
|
SCRIPT_PID=$$
|
||||||
|
|
||||||
|
#### PoorMansRandomGenerator SUBSET ####
|
||||||
|
# Get a random number of digits length on Windows BusyBox alike, also works on most Unixes that have dd
|
||||||
|
function PoorMansRandomGenerator {
|
||||||
|
local digits="${1}" # The number of digits to generate
|
||||||
|
local number
|
||||||
|
|
||||||
|
# Some read bytes can't be used, se we read twice the number of required bytes
|
||||||
|
dd if=/dev/urandom bs=$digits count=2 2> /dev/null | while read -r -n1 char; do
|
||||||
|
number=$number$(printf "%d" "'$char")
|
||||||
|
if [ ${#number} -ge $digits ]; then
|
||||||
|
echo ${number:0:$digits}
|
||||||
|
break;
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
#### PoorMansRandomGenerator SUBSET END ####
|
||||||
|
|
||||||
|
# Initial TSTMAP value before function declaration
|
||||||
|
TSTAMP=$(date '+%Y%m%dT%H%M%S').$(PoorMansRandomGenerator 5)
|
||||||
|
|
||||||
LOCAL_USER=$(whoami)
|
LOCAL_USER=$(whoami)
|
||||||
LOCAL_HOST=$(hostname)
|
LOCAL_HOST=$(hostname)
|
||||||
|
|
||||||
|
@ -119,31 +141,11 @@ fi
|
||||||
## If the same program gets remotely executed, add _REMOTE_EXECUTION=true to it's environment so it knows it has to write into a separate directory
|
## If the same program gets remotely executed, add _REMOTE_EXECUTION=true to it's environment so it knows it has to write into a separate directory
|
||||||
## This will thus not affect local $RUN_DIR variables
|
## This will thus not affect local $RUN_DIR variables
|
||||||
if [ "$_REMOTE_EXECUTION" == true ]; then
|
if [ "$_REMOTE_EXECUTION" == true ]; then
|
||||||
mkdir -p "$RUN_DIR/$PROGRAM.remote"
|
mkdir -p "$RUN_DIR/$PROGRAM.remote.$SCRIPT_PID.$TSTAMP"
|
||||||
RUN_DIR="$RUN_DIR/$PROGRAM.remote"
|
RUN_DIR="$RUN_DIR/$PROGRAM.remote.$SCRIPT_PID.$TSTAMP"
|
||||||
fi
|
fi
|
||||||
#### RUN_DIR SUBSET END ####
|
#### RUN_DIR SUBSET END ####
|
||||||
|
|
||||||
#### PoorMansRandomGenerator SUBSET ####
|
|
||||||
# Get a random number of digits length on Windows BusyBox alike, also works on most Unixes that have dd
|
|
||||||
function PoorMansRandomGenerator {
|
|
||||||
local digits="${1}" # The number of digits to generate
|
|
||||||
local number
|
|
||||||
|
|
||||||
# Some read bytes can't be used, se we read twice the number of required bytes
|
|
||||||
dd if=/dev/urandom bs=$digits count=2 2> /dev/null | while read -r -n1 char; do
|
|
||||||
number=$number$(printf "%d" "'$char")
|
|
||||||
if [ ${#number} -ge $digits ]; then
|
|
||||||
echo ${number:0:$digits}
|
|
||||||
break;
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
#### PoorMansRandomGenerator SUBSET END ####
|
|
||||||
|
|
||||||
# Initial TSTMAP value before function declaration
|
|
||||||
TSTAMP=$(date '+%Y%m%dT%H%M%S').$(PoorMansRandomGenerator 5)
|
|
||||||
|
|
||||||
# Default alert attachment filename
|
# Default alert attachment filename
|
||||||
ALERT_LOG_FILE="$RUN_DIR/$PROGRAM.$SCRIPT_PID.$TSTAMP.last.log"
|
ALERT_LOG_FILE="$RUN_DIR/$PROGRAM.$SCRIPT_PID.$TSTAMP.last.log"
|
||||||
|
|
||||||
|
@ -422,6 +424,11 @@ function KillAllChilds {
|
||||||
#### CleanUp SUBSET ####
|
#### CleanUp SUBSET ####
|
||||||
function CleanUp {
|
function CleanUp {
|
||||||
if [ "$_DEBUG" != true ]; then
|
if [ "$_DEBUG" != true ]; then
|
||||||
|
# Removing optional remote $RUN_DIR that goes into local $RUN_DIR
|
||||||
|
if [ -d "$RUN_DIR/$PROGRAM.remote.$SCRIPT_PID.$TSTAMP" ]; then
|
||||||
|
rm -rf "$RUN_DIR/$PROGRAM.remote.$SCRIPT_PID.$TSTAMP"
|
||||||
|
fi
|
||||||
|
# Removing all temporary run files
|
||||||
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID.$TSTAMP"
|
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID.$TSTAMP"
|
||||||
# Fix for sed -i requiring backup extension for BSD & Mac (see all sed -i statements)
|
# Fix for sed -i requiring backup extension for BSD & Mac (see all sed -i statements)
|
||||||
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID.$TSTAMP.tmp"
|
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID.$TSTAMP.tmp"
|
||||||
|
|
Loading…
Reference in New Issue