« Addendum to Windows Mobile Post | Main | One More Windows Mobile Find »

Cron Annoyances

After a lot of pondering and cursing cron's lack of error logs, I discovered today that apparently cron does not support using the modulus operator in a job. As an example, here's a snippet of what I've been trying to run nightly:

HOSTVAR="0$((`hostname -i | cut -d '.' -f 4` % 8))"; TIMEVAR="`date +%H`"

Simple enough, right? We create a $HOSTVAR and a $TIMEVAR based, respectively, on the last octet of the current host's IP address and the current hour of the day. This works fine from within a shell script outside of cron, but when copied directly into the cron job, we get this in the logs:

CMD (HOSTVAR="0$((`hostname -i | cut -d '.' -f 4` )

I've never run into a command that just wouldn't run from within cron, but no amount of fiddling with escapes or quotes seems to help. Maybe I'm just nuts for wanting to run everything from within my cron file instead of from its own script that cron calls. But I was hoping to keep things more condensed so I don't have more files floating around than I need, especially since the entire script is only 8 lines.

I'll have to play with this some more later, but at least the job is working now.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on July 19, 2007 10:46 AM.

The previous post in this blog was Addendum to Windows Mobile Post.

The next post in this blog is One More Windows Mobile Find.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.34