Rewrote the crontab settings, hopefully it is more secure and more accurate.
This commit is contained in:
parent
24e3fb36bc
commit
5c5fdc0553
@ -18,34 +18,45 @@ if [ "$1" == "--cron" ] ; then
|
|||||||
"to view your settings."
|
"to view your settings."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
crontab -l > /tmp/cron.bak
|
crontabFile="$(mktemp)"
|
||||||
read -p "You are about to modify talking-clock settings. Are you sure you want to do this? (Only y or Y confirms, anything else cancels) ", answer
|
crontab -l > "$crontabFile"
|
||||||
if [[ "$answer" != "y" && "$answer" != "Y" ]] ; then
|
read -n1 -p "You are about to modify talking-clock settings. Are you sure you want to do this? (Only y or Y confirms, anything else cancels) ", answer
|
||||||
|
if [ "${answer^}" != "Y" ]; then
|
||||||
echo "talking-clock settings unchanged."
|
echo "talking-clock settings unchanged."
|
||||||
|
rm "$crontabFile"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
sed -i -r '/^.*talking-clock.*$/d' /tmp/cron.bak
|
sed -i -r '/^.*talking-clock.*$/d' "$crontabFile"
|
||||||
newCron=$(cat /tmp/cron.bak)
|
|
||||||
case "$2" in
|
case "$2" in
|
||||||
"1")
|
"1")
|
||||||
#Chime once per hour.
|
#Chime once per hour.
|
||||||
newCron="$newCron\n#talking-clock settings\n0 * * * * talking-clock > /dev/null"
|
echo "# talking-clock settings" >> "$crontabFile"
|
||||||
|
echo '0 * * * * /usr/bin/talking-clock &> /dev/null' >> "$crontabFile"
|
||||||
;;
|
;;
|
||||||
"2")
|
"2")
|
||||||
#Chime twice per hour.
|
#Chime twice per hour.
|
||||||
newCron="$newCron\n#talking-clock settings\n0,30 * * * * talking-clock > /dev/null"
|
echo "# talking-clock settings" >> "$crontabFile"
|
||||||
|
echo '0,30 * * * * talking-clock &> /dev/null' >> "$crontabFile"
|
||||||
;;
|
;;
|
||||||
"4")
|
"4")
|
||||||
#Chime four times per hour.
|
#Chime four times per hour.
|
||||||
newCron="$newCron\n#talking-clock settings\n0,15,30,45 * * * * talking-clock > /dev/null"
|
echo "# talking-clock settings" >> "$crontabFile"
|
||||||
|
echo '0,15,30,45 * * * * talking-clock &> /dev/null' >> "$crontabFile"
|
||||||
esac
|
esac
|
||||||
#write new cron to temperary file.
|
|
||||||
echo -e "$newCron" > /tmp/cron.bak
|
|
||||||
#install the new cron file.
|
#install the new cron file.
|
||||||
if [ -f /tmp/cron.bak ] ; then
|
if [ -f/"$crontabFile" ]; then
|
||||||
crontab /tmp/cron.bak
|
if crontab "$crontabFile" ; then
|
||||||
echo "talking-clock settings updated."
|
echo "talking-clock settings updated."
|
||||||
exit 0
|
rm "$crontabFile"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "There was an error installing the new crontab file."
|
||||||
|
rm "$crontabFile"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Couldn't create new crontab."
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user