/var/log/mandarg

Mandar Gokhale's weblog on the internets

Email Yourself a New Link Every Day

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.

Get a new link every day from a list of links
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#! /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…

Get a new link every day from a list of links
1
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.

❧ Suggestions, comments, etc. can be emailed to comments@mandarg.com.