News for hackers. Stuff that matters.
Re:A cron pitfall that will probably snare you at least once... by js2 on Monday June 27, 2011 @11:33AM (#2701656)
Frustrating Unix pitfall of the day: esoteric cron rules

This isn't a Unix pitfall, it's a Debian pitfall. Further, it's not inherent to cron, but to the /etc/cron.{hourly,daily,weekly,monthly} concept as implemented by Debian.

Scripts in these directories are run via /usr/bin/run-parts, which is invoked via /etc/crontab. It is Debian's run-parts that imposes the naming restriction. Red Hat's run-parts doesn't have this restriction (go take a look, it's a shell script).

Re:A cron pitfall that will probably snare you at least once... by hollerith on Monday June 27, 2011 @12:49PM (#2701953)
>This isn't a Unix pitfall, it's a Debian pitfall.

And that is an example of why I do not run Debian any more: (1) it assumes that I have nothing better to do than learn all of the details of the Debian system and (2) as soon as some complication like this dots-in-filenames thing makes it into stable, it is very difficult to remove because most Debian maintainers consider it-might-break-existing-code a winning argument.

Re:A cron pitfall that will probably snare you at least once... by barrkel on Monday June 27, 2011 @09:27PM (#2703660)
"It might break existing code" is usually a winning argument. It takes a very strong opposing argument to beat it. If you don't believe in this, I don't want to use any of your code.
Re:A cron pitfall that will probably snare you at least once... by hollerith on Tuesday June 28, 2011 @08:26PM (#2707938)
I can see how server software needs to be more conservative about making changes. I'm glad I am not using server software anymore for my personal software environment.
Re:A cron pitfall that will probably snare you at least once... by pyre on Monday June 27, 2011 @11:41PM (#2703976)
On the other hand, CentOS 5 has run-parts, but it doesn't have a --help option or a manpage. The Debian one does.
Re:A cron pitfall that will probably snare you at least once... by ramidarigaz on Monday June 27, 2011 @06:39PM (#2703269)
What do you use instead?
Re:A cron pitfall that will probably snare you at least once... by Nick_C on Monday June 27, 2011 @10:51PM (#2703834)
Slackware. As usual, takes the good bits out of both RedHat's and Debian's run-parts. It allows .{whatever} but ignores obvious, well-known suffixes like .bak etc.

From man run-parts: run-parts automatically skips files with certain suffixes that are generally associated with backup or extra files. Any file that ends in one of these will be silently ignored: ~ ^ , .bak .new .rpmsave, .rpmorig .rpmnew .swp

Re:A cron pitfall that will probably snare you at least once... by maratd on Monday June 27, 2011 @08:48PM (#2703574)
CentOS/Redhat or you could go full Unix with FreeBSD. Lots of other options too.
Re:A cron pitfall that will probably snare you at least once... by hollerith on Tuesday June 28, 2011 @08:19PM (#2707923)
I switched to OS X in 2009. At the point I had been running Linux for 12 years, and GNU and Emacs on proprietary Unix for the 5 years before that.
Re:A cron pitfall that will probably snare you at least once... by hollerith on Tuesday June 28, 2011 @08:16PM (#2707918)
I was a Linux user since 1997, but switched to OS X in 2009.
Re:A cron pitfall that will probably snare you at least once... by tedunangst on Monday June 27, 2011 @12:12PM (#2701825)
Thank you for that clarification. I've been running shell scripts named .sh all the time without trouble. Of course, I run them from crontab. I'd never even heard of this /etc/cron.* thing.
Re:A cron pitfall that will probably snare you at least once... by sliverstorm on Monday June 27, 2011 @02:46PM (#2702467)
It's somewhat nifty, I suspect it originated as a way to allow new packages to easily add jobs to cron if they need
Re:A cron pitfall that will probably snare you at least once... by gwern on Monday June 27, 2011 @08:36PM (#2703547)
That's what Krafft says in _The Debian System_, actually - that it would be a real mess if new packages all had to edit the same crontab to install and deinstall themselves, but a directory-based system was very clean.
Re:A cron pitfall that will probably snare you at least once... by raldi on Monday June 27, 2011 @05:41PM (#2703130)
Hey, when you only get 80 characters for the headline, certain things have to be glossed over.
Re:A cron pitfall that will probably snare you at least once... by nbpoole on Monday June 27, 2011 @11:03AM (#2701527)
I found an older bug report for Debian that sheds a little light on why this behavior is useful: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=308911

    I can understand not changing the behaviour wrt historical
    precedent: I have been told that people used to rely on the
    ignore-dot mechanism to disable things (e.g. mv foo foo.disabled).
At the end of the report, you can see they added the --regex flag to allow for user-defined filename validation.
Re:A cron pitfall that will probably snare you at least once... by raldi on Monday June 27, 2011 @11:27AM (#2701625)
They could at least log the skipping, by default.
Re:A cron pitfall that will probably snare you at least once... by ars on Monday June 27, 2011 @11:17PM (#2703909)
Considering how often these files are run that would make for quite a noisy logfile.
Re:A cron pitfall that will probably snare you at least once... by jsprinkles on Monday June 27, 2011 @11:54AM (#2701747)
Shhh! Don't make administrators' jobs easier! How else will we justify our insane salary and benefits?

Look at the bright side: this is a few days of debugging and difficult to explain to the people signing your check. Aren't you glad it's there now?

Re:A cron pitfall that will probably snare you at least once... by kaerast on Monday June 27, 2011 @01:57PM (#2702253)
A few days debugging? How could this possibly take any more than 5 minutes to work out on your own? If it takes a few days then maybe you are in the wrong job.
Re:A cron pitfall that will probably snare you at least once... by tvon on Monday June 27, 2011 @02:15PM (#2702358)
I think "a few days" was an intentional exaggeration.
Re:A cron pitfall that will probably snare you at least once... by jerf on Monday June 27, 2011 @10:17AM (#2701356)
Asked there, but I'll tack it on here too: What is the purpose of that absurd-seeming restriction on file names? If you can drop arbitrary executables into directories on the file system, you've already "won", so I assume it's not security. I've read the run-parts man page, and that just pushes the problem back one level. If it's just to avoid running old files, that's an absurdly large hammer to hit that problem with.
Re:A cron pitfall that will probably snare you at least once... by raldi on Monday June 27, 2011 @10:28AM (#2701392)
My guess is they wanted to avoid running .dotfiles and #emacsbackup~ files and threw out the baby with the bathwater.
Re:A cron pitfall that will probably snare you at least once... by pyre on Monday June 27, 2011 @10:58AM (#2701511)
Also '.bak' or '.old'
Re:A cron pitfall that will probably snare you at least once... by qntm on Tuesday June 28, 2011 @08:59AM (#2705182)
Isn't ".bak" a fairly logical file extension for a cron job intended to, e.g., perform backups?
Re:A cron pitfall that will probably snare you at least once... by dexen on Monday June 27, 2011 @03:22PM (#2702604)
Are #emacsbackup~ files executable by default? If not, that's a very weak reason.

(honestly I dunno; have never used EMACS yet)

Re:A cron pitfall that will probably snare you at least once... by raldi on Monday June 27, 2011 @05:46PM (#2703138)
Well, # is actually used for emacs autosave files (or something else regarding open buffers). Making ~ backups is indeed on by default.

Then again, if you're editing files in /etc/ as root and using emacs to do so, you kinda deserve what you get.

Re:A cron pitfall that will probably snare you at least once... by dexen on Monday June 27, 2011 @05:53PM (#2703150)
Wait, my intented question was, `do those backup files have the executable permission bits set'? Not `do they hold valid input for interpreter/CPU'.

In Slackware's startup scripts, there's a good bunch of

  if [ -x SOME_FILE ]; then    # if the file is executable, run it
    ./SOME_FILE start
  fi
which makes it trivial to enable/disable various services by simply chmod +x SOME_FILE / chmod -x SOME_FILE. If EMACS' backup files were marked as not executable by the editor, that would be `case closed' for me, no need to pay extra attention to characters in file names.
Re:A cron pitfall that will probably snare you at least once... by ars on Monday June 27, 2011 @11:14PM (#2703905)
Yes, backup files have the executable bit set. They have the same bits as the real file.

They are in fact created by renaming the real file to the backup name, then saving the real file and copying the permissions.

Re:A cron pitfall that will probably snare you at least once... by insipid on Monday June 27, 2011 @11:21AM (#2701604)
According to the summary on the Ubuntu bug: "Essentially, we don't want to allow a '.' because of .dpkg-old and .dpkg-dist files."

Is the implication that you can have .dpkg files in cron folders that you wouldn't want to try to execute?

https://bugs.launchpad.net/ubuntu/+source/debianutils/+bug/3... http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=68561

Re:A cron pitfall that will probably snare you at least once... by nbpoole on Monday June 27, 2011 @11:23AM (#2701610)
I posted a link (http://news.ycombinator.com/item?id=2701527) to a Debian bug that explains the rationale (aside from the historical behavior argument) a little better: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=308911
Re:A cron pitfall that will probably snare you at least once... by insipid on Monday June 27, 2011 @03:14PM (#2702573)
My apologies; I must have missed the comments in between my first looking at it and posting my comment.
Re:A cron pitfall that will probably snare you at least once... by cperciva on Monday June 27, 2011 @10:28AM (#2701400)
I have no clue why run-parts does this; but BSD periodic doesn't.
Re:A cron pitfall that will probably snare you at least once... by mikemaccana on Monday June 27, 2011 @11:35AM (#2701669)
Yes, it's not a bug in Vixie Cron (which I think BSD cron may use) but in the Linux distros (who are responsible for adding run-parts).

.py, .pl, .sh and (as people realize they'are actually writing bash scripts) .bash are standards people actually use. Having them break in what amounts to an include dir is bad mojo.

Re:A cron pitfall that will probably snare you at least once... by cperciva on Monday June 27, 2011 @12:58PM (#2701999)
I can't speak for other BSDs, but FreeBSD's cron is still derived from Vixie cron.
Re:A cron pitfall that will probably snare you at least once... by RexRollman on Monday June 27, 2011 @02:27PM (#2702410)
OpenBSD uses Vixie Cron as well.
Re:A cron pitfall that will probably snare you at least once... by yock on Monday June 27, 2011 @11:01AM (#2701520)
I think I'm missing something. The comments that appear as if they should contain the answers contain nothing. Have the answers been removed? Does Reddit's [spoiler] tag do fun javascript-y things that don't work on IE8? Or am I so obtuse and unobservant that I'm missing something obvious?
Re:A cron pitfall that will probably snare you at least once... by randombit on Monday June 27, 2011 @11:06AM (#2701546)
They show up as a hovertext in FF
Re:A cron pitfall that will probably snare you at least once... by gcb on Monday June 27, 2011 @11:41AM (#2701701)
useless on android
Re:A cron pitfall that will probably snare you at least once... by GrooveStomp on Monday June 27, 2011 @03:10PM (#2702554)
Yeah, it wasn't working on my Android phone either. Had to wait to get into work and try it with Chrome.
Re:A cron pitfall that will probably snare you at least once... by mthomas on Monday June 27, 2011 @11:08AM (#2701548)
You simply highlight the blocked text to reveal it. The text is the same color as the background.
Re:A cron pitfall that will probably snare you at least once... by yock on Monday June 27, 2011 @11:28AM (#2701629)
That was the first thing I tried, to no avail. I was able to see his response by going to his profile and hovering over the word "spoiler" in his comment stream. The word "spoiler" doesn't appear for me in the threaded comments and clicking through the word "spoiler" results in a 404.

Very strange.

Re:A cron pitfall that will probably snare you at least once... by nbpoole on Monday June 27, 2011 @11:57AM (#2701765)
That has to do with how spoiler tags are set up on that subreddit: the actual spoiler content is in the title attribute of the link and the href points to /s. The CSS for the subreddit uses an attribute selector to find links pointing to /s and styles them appropriately.

If you view the posts outside of the context of the subreddit, there's no special CSS, so the link appears normally with some title text that appears on hover.

Re:A cron pitfall that will probably snare you at least once... by nbpoole on Monday June 27, 2011 @11:04AM (#2701534)
Click and drag over the text with your mouse and you should be able to see it.
Re:A cron pitfall that will probably snare you at least once... by bmunro on Monday June 27, 2011 @11:06AM (#2701544)
That was the first thing I tried. It doesn't work for me in Chromium 12
Re:A cron pitfall that will probably snare you at least once... by trafficlight on Monday June 27, 2011 @11:22AM (#2701606)
Me either. But if you double click on the block it will highlight the text.
Re:A cron pitfall that will probably snare you at least once... by nbpoole on Monday June 27, 2011 @11:09AM (#2701552)
Strange. I'm running Chrome 12 on OS X and I have no issue (although the contrast is very poor).
Re:A cron pitfall that will probably snare you at least once... by raldi on Monday June 27, 2011 @11:29AM (#2701635)
Really? I tried to set up the CSS so it would be white on black. What colors do you actually get?
Re:A cron pitfall that will probably snare you at least once... by nbpoole on Monday June 27, 2011 @11:33AM (#2701657)
Screenshot: http://imgur.com/Uq9Fs

I'm just hoping I'm not color-blind :-P

Re:A cron pitfall that will probably snare you at least once... by jsprinkles on Monday June 27, 2011 @11:56AM (#2701756)
All of the spoiler CSS (Reddit-wide) broke for me a few Chromes ago. Running 14.0.797.0 now on OS X.
Re:A cron pitfall that will probably snare you at least once... by technomancy on Monday June 27, 2011 @05:07PM (#2703019)
Another fun one is that if your file doesn't end in a newline, cron will silently ignore the last line! Lost a couple days of production data at my last job due to that "feature".
Re:A cron pitfall that will probably snare you at least once... by oasisbob on Monday June 27, 2011 @06:39PM (#2703270)
IIRC, OpenBSD has some similar issues with PF rules, and perhaps other configuration files as well.

I can't remember if it refuses to parse the file or ignores the last line, but it's not a fun thing to bump against.

Re:A cron pitfall that will probably snare you at least once... by there on Tuesday June 28, 2011 @12:29AM (#2704081)
what editor are you using that doesn't add a newline?
Re:A cron pitfall that will probably snare you at least once... by mseebach on Monday June 27, 2011 @11:24AM (#2701612)
run-parts is used in many places on linuxes (anywhere you see a .d directory) so this is not a cron pitfall.
Re:A cron pitfall that will probably snare you at least once... by jsprinkles on Monday June 27, 2011 @11:52AM (#2701737)
You're right. Upstart does this too (if you rename to .disabled in /etc/init the job will not be run).
Re:A cron pitfall that will probably snare you at least once... by res0nat0r on Tuesday June 28, 2011 @02:49AM (#2704330)
Since everyone should hopefully know /etc/cron* is a nonstandard cron directory, and an addon from Debian, it would be hopeful that you would also have discovered the relevant documentation as why this is, ie run-parts(8), like mentioned.

The manpage states you can pass --test <dir> and it will show you all the scripts it would have run. This should have been something done before any assumption was made as to this working off the bat.

On my systems now, or old Solaris machines I used to admin, I would always do an "at now <script>" to make sure there were not any $PATH issues before putting the script in production. I've always tested to make sure the generic skeleton of the script would work before assuming anything...

Re:A cron pitfall that will probably snare you at least once... by tvon on Monday June 27, 2011 @10:27AM (#2701388)
I'd love to hear the rationale behind the dot restriction.
Re:A cron pitfall that will probably snare you at least once... by javanix on Monday June 27, 2011 @11:40AM (#2701694)
It is kind of amazing how much this explains.

I thought I was doing well when I finally learned to remember the "no cron files that don't include an empty newline" rule.

Re:A cron pitfall that will probably snare you at least once... by jwr on Monday June 27, 2011 @11:19AM (#2701596)
This bit me as well. It is particularly annoying, as it takes forever to actually find the problem.

In addition to that, the restriction is silly and utterly pointless.

Re:A cron pitfall that will probably snare you at least once... by ck2 on Monday June 27, 2011 @11:18AM (#2701589)
I don't believe CentOS distro has this problem?

I have plenty of scripts and php and such running in crons all over the place.

Re:A cron pitfall that will probably snare you at least once... by xbryanx on Monday June 27, 2011 @12:21PM (#2701850)
I've been using Jenkins to do every single thing I used to do in cron these days. Lots easier to visualize execution, and catch potential errors. More overhead, yes. Saved me tons of time, yes.
Re:A cron pitfall that will probably snare you at least once... by geuis on Monday June 27, 2011 @04:03PM (#2702783)
Why the devil can't I see certain text? I'm not a user of reddit so is this some kind of joke? I'm reading this on my iPhone.
Re:A cron pitfall that will probably snare you at least once... by whiskers on Monday June 27, 2011 @04:05PM (#2702791)
Also on an iPhone. The reason is they're using a 'spoiler' tag that hides the text until it is selected. Unfortunately we can't do that...
Re:A cron pitfall that will probably snare you at least once... by city41 on Monday June 27, 2011 @05:20PM (#2703061)
Tap the text and it will become visible, then it navigates to reddit.com/s (no idea why). Then click back and the text will still be readable (just confirmed on my iPhone 4)
Re:A cron pitfall that will probably snare you at least once... by X-Istence on Monday June 27, 2011 @08:50PM (#2703581)
It is a hack using links.

It is formatted like this (IIRC):

  [spoiler](/s"More goes here")
then in CSS there is a match for url[href=/s] that provides the onmouseover stuff.
Re:A cron pitfall that will probably snare you at least once... by chrisjsmith on Monday June 27, 2011 @10:59AM (#2701513)
Been there done that. It's very annoying indeed. I wish things were slightly less finicky in *NIX platforms as a rule. They need a serious de-crufting session (plan 9 looks very much less crufty).
Re:A cron pitfall that will probably snare you at least once... by bshep on Monday June 27, 2011 @11:15AM (#2701578)
I've been hit with this problem before and had never found an explanation why some scripts worked and some didn't.

I eventually just added it to the crontab of a user and that was that, but I'm so glad to finally know WHY.

This is such an arcane restriction and its really hard to debug since there are no errors anywhere.

Re:A cron pitfall that will probably snare you at least once... by chrisjsmith on Tuesday June 28, 2011 @04:37AM (#2704602)
The lack of errors was annoying and counterintuitive. I like the usual UNIX mantra of blow up noisily if an assumption is made but it just doesn't happen there.