I have a shell script with the following lines (the full script at the end of post):
CRON_BCK_CMD=/home/user/bck.sh
CRON_CONF=" */30 * * * * $CRON_BCK_CMD"
but when I simply run these in shell and then echo $CRON_CONF
I get
*/30 ... /home/user/bck.sh
where ...
stand for all files listed from /home/user, e.g. */30 bck.sh bck-ssh.sh Documents davmail.log.../home/user/bck.sh
The script used to work on my other machine I think. How do I do what I obviously want to do?
# SETUP
# CRON_BCK_CMD sets the full path to the backup script
CRON_BCK_CMD=/home/user/bck.sh
# CRON_CONF sets the configuration line for cron, the time is set as:
# minute hour day_of_month month day_of_week
# * means any value, eg. 15 * * * * would mean backup at any hour, any day, when minute on the clock equals 15
# repetition can be managet by /, eg. */15 * * * * means backup every 15 minutes
CRON_CONF=" */30 * * * * $CRON_BCK_CMD"
# SETUP END
CRON_IS_BCK_CMD=$(crontab -l 2>/dev/null | grep $CRON_BCK_CMD) || true
if [[ ! $CRON_IS_BCK_CMD ]]
then
echo "No entry for backup found in crontab, do you want to schedule?"
read -p "y/n (y) " REPLY
if [[ $REPLY =~ ^[n|N]$ ]]
then
echo "Nothing to do, exitting..."
exit 0
fi
(crontab -l ; echo "$CRON_CONF") | crontab -
else
echo "Found crontab entry, do you want to stop schedule?"
read -p "y/n (y) " REPLY
if [[ $REPLY =~ ^[n|N]$ ]]
then
echo "Nothing to do, exitting..."
exit 0
fi
crontab -l | grep -v $CRON_BCK_CMD | crontab -
fi
echo "$CRON_CONF"
– Quasímodo Feb 13 '20 at 23:09read -p "y/n (y) " REPLY
), read without -r will mangle backslashes. – Paulo Tomé Feb 13 '20 at 23:31