forked from axiom-team/astrXbian
Switch ASTROPORT ON / OFF
This commit is contained in:
parent
aa3a07e06a
commit
cdfe5a0bcd
|
@ -13,28 +13,39 @@ echo '
|
|||
# qo-op
|
||||
############# '$MY_PATH/$ME'
|
||||
########################################################################
|
||||
# ex: ./'$ME'
|
||||
# VERIFY CRON for cron_MINUTE.sh and ACTIVATE it
|
||||
# Activate / Desactivate ASTROPORT cron_MINUTE.sh job
|
||||
########################################################################'
|
||||
# Get crontab
|
||||
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 ?)
|
||||
crontest=$(cat /tmp/mycron | grep -F 'cron_MINUTE')
|
||||
# ADD cron_MINUTE.sh TO cron ?
|
||||
# Remove any previous line containing "SHELL & PATH"
|
||||
# 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
|
||||
# NOT LOGGING TO FILE >> /tmp/astroport.log (TO MUCH DATA)
|
||||
rm -f /tmp/newcron
|
||||
[[ ! $(cat /tmp/mycron | grep -F 'SHELL') ]] && echo "SHELL=/bin/bash" >> /tmp/newcron
|
||||
## 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
|
||||
cat /tmp/mycron >> /tmp/newcron
|
||||
# ADD cron_MINUTE.sh line
|
||||
echo "* * * * * /bin/bash $MY_PATH/../cron_MINUTE.sh 2>&1>/dev/null" >> /tmp/newcron
|
||||
crontab /tmp/newcron
|
||||
echo "ASTROPORT is ON"
|
||||
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
|
||||
|
||||
# Clean
|
||||
rm -f /tmp/mycron
|
||||
rm -f /tmp/mycron /tmp/newcron
|
||||
|
||||
exit 0
|
||||
|
|
Loading…
Reference in New Issue