All values coming from “date” are now correctly converted to integers

This commit is contained in:
pezcurrel 2024-09-08 20:29:29 +02:00
parent 9bee2ee027
commit 758e570794

View file

@ -1,4 +1,5 @@
#!/bin/bash #!/bin/bash
trap "exit" INT trap "exit" INT
basedir=`dirname "$0"` basedir=`dirname "$0"`
cd "$basedir/.." cd "$basedir/.."
@ -7,17 +8,17 @@ mailmta=`cat "${mailcfgfp}" | grep -P '^mta=' | sed -e 's/^mta=//' -e 's/^"//' -
mailfrom=`cat "${mailcfgfp}" | grep -P '^from=' | sed -e 's/^from=//' -e 's/^"//' -e 's/"$//'` mailfrom=`cat "${mailcfgfp}" | grep -P '^from=' | sed -e 's/^from=//' -e 's/^"//' -e 's/"$//'`
mailto=`cat "${mailcfgfp}" | grep -P '^to=' | sed -e 's/^to=//' -e 's/^"//' -e 's/"$//'` mailto=`cat "${mailcfgfp}" | grep -P '^to=' | sed -e 's/^to=//' -e 's/^"//' -e 's/"$//'`
subj="" subj=""
lastmailts=0 lastmailts=$((0))
newmailwait=$((12*60*60)) newmailwait=$((12*60*60))
resurrfp=".pcresurrectdone" resurrfp=".pcresurrectdone"
cmdlogfp="peerscrawl.log" cmdlogfp="peerscrawl.log"
logfp="pcloop.log" logfp="pcloop.log"
resdom=25 # day of month when (or after when, if it has not been done already) to execute peerscrawl.php with a gracetime of 2 months resdom=$((25)) # day of month when (or after when, if it has not been done already) to execute peerscrawl.php with a gracetime of 2 months
function log { function log {
echo `date "+%Y-%m-%d %H:%M:%S.%N"` "${1}" >> "${logfp}" echo `date "+%Y-%m-%d %H:%M:%S.%N"` "${1}" >> "${logfp}"
} }
while true; do while true; do
dom=$((`date "+%d"`+0)) dom=$(($(expr $(date "+%d") + 0)))
[ $dom -lt $resdom -a -f "$resurrfp" ] && rm "$resurrfp" [ $dom -lt $resdom -a -f "$resurrfp" ] && rm "$resurrfp"
if [[ ($dom -ge $resdom ) && !(-f "$resurrfp") ]]; then # use a gracetime of 2 months if [[ ($dom -ge $resdom ) && !(-f "$resurrfp") ]]; then # use a gracetime of 2 months
touch "$resurrfp" touch "$resurrfp"
@ -31,11 +32,11 @@ while true; do
tail $cmdlogfp >> $logfp tail $cmdlogfp >> $logfp
log "### THE END ###" log "### THE END ###"
cp "$cmdlogfp" "${cmdlogfp}.old" cp "$cmdlogfp" "${cmdlogfp}.old"
now=$((`date "+%s"`+0)) now=$(($(expr $(date "+%s") + 0)))
if [ $(($now-$lastmailts)) -gt $newmailwait ]; then if [ $(($now-$lastmailts)) -gt $newmailwait ]; then
[ $pcrv == "0" ] && subj="peerscrawl.php: tutto ok :-)" || subj="peerscrawl.php: uscito con errore: ${pcrv} :-(" [ $pcrv == "0" ] && subj="peerscrawl.php: tutto ok :-)" || subj="peerscrawl.php: uscito con errore: ${pcrv} :-("
tail $logfp | s-nail -s "${subj}" -S v15-compat -S from="${mailfrom}" -S smtp-use-starttls -S mta="${mailmta}" "${mailto}" tail $logfp | s-nail -s "${subj}" -S v15-compat -S from="${mailfrom}" -S smtp-use-starttls -S mta="${mailmta}" "${mailto}"
lastmailts=$((`date "+%s"`+0)) lastmailts=$(($(expr $(date "+%s") + 0)))
fi fi
done done
exit 0; exit 0;