suppress certain output directly in crontab

1.9k Views Asked by At

OS: ubuntu 10.04 LTS

Hey guys

Were using a script which makes an update daily on our ubuntu machine

And the cron deamon gives a notification by mail

And alway Comes the following : stdin: is not a tty

This line i will comment out and no notifications should be sent if this error occours

Some time ago i've found a method to supress Output directly in crontab

But cannot find it anymore

Does anybody konw how to do that ?

regards John s.

2

There are 2 best solutions below

7
On

The answer to your question is the following:

5 0 * * * your_command 2>&1 | grep -v 'stdin: is not a tty'

Redirect stderr to stdout, then pipe all output through grep -v to remove that unwanted error.

Edit: slapping this in without investigating any further is a quick and dirty fix. Do it if you just need to silence those pesky emails and move on. However, you may find it more educational/beneficial in the long run to try to figure out what's causing the error, and stop it. Then, for example, if you add more cron jobs, you wouldn't have to keep adding this to every one. In the end though, you may find you have to do it anyway if it's not easy to fix the offending command.

Googling around suggests it may be caused by something in your .bashrc or /root/.profile. Check those, and fix them if needed (possibly changing mesg -n to tty -s && mesg -n).

Update your question with more information if you can't get to the bottom of it or need more ideas.

0
On

The error message:

stdin: is not a tty

suggests that something in your cron job is trying to read from standard input. A job invoked by cron should not do that (unless, of course, its standard input is redirected). A small experiment shows that a cron job's standard input is empty, and is not a tty. If I run vi as a cron job (don't try this at home), I get an odd error message by e-mail including these warnings:

Vim: Warning: Output is not to a terminal
Vim: Warning: Input is not from a terminal

So you're apparently running something in your cron job that (a) assumes it can read from stdin, and (b) assumes that stdin is connected to a terminal -- i.e., it's some kind of interactive command.

If you can, you should track down what command is making these assumptions and fix it, not just discard the error message. (The latter is reminiscent of solving the problem of a warning light on your car's dashboard by covering it with tape.)

Either don't invoke an interactive command from your crontab, or find a way to make whatever command you're invoking run in some kind of "batch mode".

It's possible, on the other hand, that there's a reason you need to run some interactive command from a cron job, and making it behave correctly is too difficult. In that case, you can discard the error message as Steve Kehlet's answer suggests.

If you have difficulty tracking down the problem, a couple of useful tricks are:

Test cron jobs by temporarily running them every minute:

* * * * * some-command

so you only have to wait less than a minute to see the results. If the command is a script, try reducing it to the minimal example that exhibits the problem.

You might also update your question to show us your crontab entry and the script you're running (if the script isn't too large).