in reply to Detecting running from cron?

I think the canonical test is -t which is the same as -t STDIN. For your case -t STDOUT might be better.

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Re: (tye)Re: Detecting running from cron?
by chipmunk (Parson) on Jan 23, 2001 at 21:20 UTC
    -t STDIN is definitely very useful; it tells you whether the script is running interactively. But keep in mind that a script can be run from the command line without being run interactively: echo "Hi!" | perl -wle 'print -t() ? "" : "not ", "interactive"' So it might not do what the original poster wants in this case.

      Thank you. I was relying on the readers to consult the manual on -t (especially since I didn't say whether a true or false value from -t meant "running from cron"). But that was a pretty poor assumption on my part.

      Reading between the lines of the question, I got the impression that the stuff going to STDOUT was meant only to be seen by interactive users, which is why I suggested -t STDOUT. Thinking on it more, I think a better test for this case is -t STDERR so that script <input | more would be considered "interactive" while the cron case specifically stated that STDERR was redirected to a file.

              - tye (but my friends call me "Tye")