Email yourself a new link every day

Posted 1427155200 seconds after the Unix epoch

I often gather tons of links which I propose to read later, and never end up doing so. So I decided to write myself a simple utility that I could run on my server, to email me one of these.

#! /bin/bash

COUNTER_FILE='/tmp/.number'

if [[ -r $COUNTER_FILE ]] ; then
    count=$(cat ${COUNTER_FILE})
else
    count=1
fi

MESSAGE=$(sed -n ${count}p $1)

echo $MESSAGE
count=$((count+1))

echo $count > ${COUNTER_FILE}

Now, all I have to do is to add the following to my crontab…

0 14 * * * /home/user/scripts/newlink /home/user/text/links.txt | mail -s "Link for $(date +'\%d \%B \%Y')" links@mandarg.com

…and I have a fresh link every morning. Linkbait for the win.

Note: The cronjob didn’t initially work as I had expected, because % signs indicate new lines in a crontab, and have to be escaped. Good to know.


❧ Please send me your suggestions, comments, etc. at comments@mandarg.com