I might be able to learn from your outer loop, actually--this is close to a much simpler problem I've needed to solve.
I take my notes in markdown bulleted lists, and try to make them very narrow so they fit on the side of my monitor. I shorten all my links to keep the character count down. The shortener we use at work times out the links if they're not used, though, so in old notes I can go back and discover my alias is gone.
I've been meaning to write something that just sweeps my notes and hits the links through the shortener URL periodically as a keepalive. Since the notes are not always conveniently in one tree with nothing else around, I was thinking something a little richer than text extraction piped to curl.
If nothing else, maybe this'll inspire me to get off my ass and actually get it done.