Switch ASTROPORT ON / OFF

This commit is contained in:
fred 2021-09-06 01:04:57 +02:00
parent aa3a07e06a
commit cdfe5a0bcd
1 changed files with 23 additions and 12 deletions

View File

@ -13,28 +13,39 @@ echo '
# qo-op # qo-op
############# '$MY_PATH/$ME' ############# '$MY_PATH/$ME'
######################################################################## ########################################################################
# ex: ./'$ME' # Activate / Desactivate ASTROPORT cron_MINUTE.sh job
# VERIFY CRON for cron_MINUTE.sh and ACTIVATE it
########################################################################' ########################################################################'
# Get crontab # Get crontab
crontab -l > /tmp/mycron crontab -l > /tmp/mycron
# Remove any previous line containing "cron_MINUTE"
awk -i inplace -v rmv="cron_MINUTE" '!index($0,rmv)' /tmp/mycron
# DOUBLE CHECK (awk = nawk or gawk -i ?) # DOUBLE CHECK (awk = nawk or gawk -i ?)
crontest=$(cat /tmp/mycron | grep -F 'cron_MINUTE') # Remove any previous line containing "SHELL & PATH"
# ADD cron_MINUTE.sh TO cron ? # awk -i inplace -v rmv="cron_MINUTE" '!index($0,rmv)' /tmp/mycron
awk -i inplace -v rmv="SHELL" '!index($0,rmv)' /tmp/mycron
awk -i inplace -v rmv="PATH" '!index($0,rmv)' /tmp/mycron
crontest=$(cat /tmp/mycron | grep -F 'cron_MINUTE.sh')
if [[ ! $crontest ]]; then if [[ ! $crontest ]]; then
# NOT LOGGING TO FILE >> /tmp/astroport.log (TO MUCH DATA) ## HEADER
rm -f /tmp/newcron [[ ! $(cat /tmp/mycron | grep -F 'SHELL') ]] && echo "SHELL=/bin/bash" > /tmp/newcron
[[ ! $(cat /tmp/mycron | grep -F 'SHELL') ]] && echo "SHELL=/bin/bash" >> /tmp/newcron [[ ! $(cat /tmp/mycron | grep -F 'PATH') ]] && echo "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" >> /tmp/newcron
[[ ! $(cat /tmp/mycron | grep -F 'PATH') ]] && echo "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" >> /tmp/newcron
cat /tmp/mycron >> /tmp/newcron cat /tmp/mycron >> /tmp/newcron
# ADD cron_MINUTE.sh line
echo "* * * * * /bin/bash $MY_PATH/../cron_MINUTE.sh 2>&1>/dev/null" >> /tmp/newcron echo "* * * * * /bin/bash $MY_PATH/../cron_MINUTE.sh 2>&1>/dev/null" >> /tmp/newcron
crontab /tmp/newcron crontab /tmp/newcron
echo "ASTROPORT is ON"
else else
echo "No operation needed. Your crontab is: " && crontab -l ## HEADER
[[ ! $(cat /tmp/mycron | grep -F 'SHELL') ]] && echo "SHELL=/bin/bash" > /tmp/newcron
[[ ! $(cat /tmp/mycron | grep -F 'PATH') ]] && echo "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" >> /tmp/newcron
## REMOVE cron_MINUTE.sh line
cat /tmp/mycron | grep -Ev 'cron_MINUTE.sh' >> /tmp/newcron
crontab /tmp/newcron
echo "ASTROPORT is OFF"
fi fi
# Clean # Clean
rm -f /tmp/mycron rm -f /tmp/mycron /tmp/newcron
exit 0 exit 0