Pop Quiz: Spot the Bug, CRON Edition

That's right boys & girls, its quiz time. Get out your brains and prepare to use them.

The file below is a standard cronjob file, hiding in /etc/cron.d. Can anyone point out to me what the bug is? Assume that some_script exists and produces output. And yes there is a bug in there. I promise.

  1. 55 14 * * * root sleep $(($RANDOM % 60)); logger -p local3.info "some script"; OUT=`/opt/sbin/some_script 2>&1` ; logger -p local3.info $OUT;

Unless someone posts a comment with the correct answer( and earns themselves a virtual beer), I will share the answer next week.

From the Tagged SiteOps Team

You need to escape the '%' in the sleep section because % means newline in crontabs.

Cheers,

-Dave

Hey Dave, Thanks for posting

Hey Dave,

Thanks for posting the right answer. Happy Easter to you and yours, and I'll send you that virtual beer as soon as I can.

For anyone who is interested in the details, if you run:

man 5 crontab

you'll eventually see this paragraph:


Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.

Happy Easter everyone!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <geshi>, <c>, <cpp>, <drupal5>, <drupal6>, <haskell>, <java>, <javascript>, <perl>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].

More information about formatting options

If you made it this far down into the article, hopefully you liked it enough to share it with your friends. Thanks if you do, I appreciate it.

Bookmark and Share