forked from axiom-team/astrXbian
52 lines
2.0 KiB
Bash
Executable File
52 lines
2.0 KiB
Bash
Executable File
#!/bin/bash
|
|
########################################################################
|
|
# Author: Fred (support@qo-op.com)
|
|
# Version: 2020.03.21
|
|
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
|
|
########################################################################
|
|
MY_PATH="`dirname \"$0\"`" # relative
|
|
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
|
|
ME="${0##*/}"
|
|
echo '
|
|
########################################################################
|
|
# \\///
|
|
# qo-op
|
|
############# '$MY_PATH/$ME'
|
|
########################################################################
|
|
# Activate / Desactivate ASTROPORT cron_MINUTE.sh job
|
|
########################################################################'
|
|
# Get crontab
|
|
crontab -l > /tmp/mycron
|
|
|
|
# DOUBLE CHECK (awk = nawk or gawk -i ?)
|
|
# 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
|
|
## 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
|
|
## 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 /tmp/newcron
|
|
|
|
exit 0
|