Is there a standard way to know if a shell script is running under cron as opposed to running from the command line. i.e. I'm thinking of running with more verbose output when manually kicked from the command line and enabling some features that only run when under cron.

  • 1
    Hello Stuart. I'm sure you've already tried it but would it be possible to differentiate using the user id? Jan 8 '15 at 5:07
  • 2
    As far as I know there isn't and there shouldn't be a difference in how a script runs, as that would make debugging nigh impossible rather than easier . Simply build in support for a debug flag or similar if you want an easy way to increase verbosity e.g. support a -v flag with getopts
    – HBruijn
    Jan 8 '15 at 5:59
  • 1
  • Is output from the "tty" command different?
    – Andy
    Jan 8 '15 at 6:52
  • @HBruijn, excellent suggestion. If verbosity should be the default, add a -q option for running quietly. Jan 8 '15 at 12:06

Since posting the question I have found the same question answered on Stack Exchange:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.