You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

40 lines
1.6 KiB

#!/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'
########################################################################
# ex: ./'$ME'
# VERIFY CRON for cron_MINUTE.sh and ACTIVATE it
########################################################################'
# 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 ?
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
[[ ! $(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
echo "* * * * * /bin/bash $MY_PATH/../cron_MINUTE.sh 2>&1>/dev/null" >> /tmp/newcron
crontab /tmp/newcron
else
echo "No operation needed. Your crontab is: " && crontab -l
fi
# Clean
rm -f /tmp/mycron
exit 0