Operating System - HP-UX
1822896 Members
3577 Online
109645 Solutions
New Discussion юеВ

Getting a message "mesg: not a tty" from cron (root's mail)

 
SOLVED
Go to solution
MAD_2
Super Advisor

Getting a message "mesg: not a tty" from cron (root's mail)

Sorry, I had to re-post this message with a "complete subject" (I wish there was a way for the creator of the message to fix a mistake like this, one -- User error!)

Recently, my root's mailbox had an overflow. However, I am starting to get these messages from our cron jobs (mesg: not a tty). Any idea of why or how to resolve it?

This is for jobs that should not be producing output unless there is actually an error on the script.

============================================

# mail
From root@hostname.domain.com Mon Nov 4 12:22:18 EST 2002
Received: (from root@localhost)by hostname.domain.com (8.9.3 (PHNE_24419)/8.9.3) id MAA01501 for root; Mon, 4 Nov 2002 12:22:17 -0500 (EST)
Date: Mon, 4 Nov 2002 12:22:17 -0500 (EST)
From: root@hostname.domain.com
Message-Id: <200211041722.MAA01501@hostname.domain.com>

Subject: cron
mesg: not a tty
mesg: not a tty
***********************************************Cron: The previous message is the standard output and standard error of one of your ccrontab commands:

/usr/rcsd/bin/chk_syslinks.sh
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
12 REPLIES 12
Patrick Wallek
Honored Contributor

Re: Getting a message "mesg: not a tty" from cron (root's mail)

OK, I'm reposting my previous response:

"This is most likely due to the fact that you are sourcing a file, like a users .profile, that is attempting to set environment variables that are designed to be used with an interactive terminal and not with a non-interactive terminal like a cron job. "

Now, you said that this just started happening. The first question I'll ask is: What changed?

Did you make a change to something like .profile or any other . files that a cron job may source? Things don't usually change the way they behave without something else changing somewhere.
steven Burgess_2
Honored Contributor

Re: Getting a message "mesg: not a tty" from cron (root's mail)

Hi

What happens if there is an error , does it write to the error log ? and not give the tty message ? If so , try and redirect stdout within your cron job to /dev/null or a character device file

HTH

Steve
take your time and think things through
MAD_2
Super Advisor

Re: Getting a message "mesg: not a tty" from cron (root's mail)

OK, let me give you all an example of what was a normal message and what I am getting now. Patrick, there has been no changes to profile or the scripts. The only thing that happened between then and now is that the mailbox suffered an overflow recently.

What seemed normal (resulted from an error encountered during execution -- No errors = no message):

From root@hostname.domain.com Sun May 12 17:40:03 EDT 2002
Received: (from root@localhost) by hostname.domain.com (8.9.3 (PHNE_24419)/8
.7.1) id RAA03453 for root; Sun, 12 May 2002 17:40:03 -0400 (EDT)
Date: Sun, 12 May 2002 17:40:03 -0400 (EDT)
From: root@hostname.domain.com
Message-Id: <200205122140.RAA03453@hostname.domain.com>
Subject: cron
Status: O

cat: Cannot open /tmp/get_date.3438: No such file or directory
cat: Cannot open /tmp/get_date.3443: No such file or directory


*************************************************
Cron: The previous message is the standard output
and standard error of one of your crontab commands:

/usr/rcsd/bin/wcanjobs.sh # WCAN Tasks


=============================================
What I get now:

From root@hostname.domain.com Mon Nov 4 13:20:01 EST 2002
Received: (from root@localhost)
by hostname.domain.com (8.9.3 (PHNE_24419)/8.9.3) id NAA08811
for root; Mon, 4 Nov 2002 13:20:01 -0500 (EST)
Date: Mon, 4 Nov 2002 13:20:01 -0500 (EST)
From: root@hostname.domain.com
Message-Id: <200211041820.NAA08811@hostname.domain.com>
Subject: cron

mesg: not a tty


*************************************************
Cron: The previous message is the standard output
and standard error of one of your crontab commands:

/usr/rcsd/bin/wcanjobs.sh # WCAN Tasks
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
MAD_2
Super Advisor

Re: Getting a message "mesg: not a tty" from cron (root's mail)

The problem I have here is that some of these cronjobs run every 10 minutes or so, and others run about ever 20 or 30 minutes. They did not produce a message before unless there was an error when the script executed, which was not much of a problem because I would rarely see an error occur.

However, since this new problem is seen as an error I am getting a message every time the jobs run.
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
John Palmer
Honored Contributor

Re: Getting a message "mesg: not a tty" from cron (root's mail)

Hi,

I agree with Patrick, what's changed? I'd be looking through the cron'd script to find out what's calling the 'mesg' command. This is designed only to be run in a terminal session and has no meaning in a cron's job.

Are you sure you're not running su - somewhere and causing a .profile to be run?

Regards,
John
MAD_2
Super Advisor

Re: Getting a message "mesg: not a tty" from cron (root's mail)

100% sure, no changes on .profile, no changes on the scripts, no "su", no changes on cron.. Let me show you our crontab entries for the jobs shown in my examples. They remain the same.

=========================================

00,10,20,30,40,50 * * * * /usr/rcsd/bin/chk_syslinks.sh

20,40 * * * * /usr/rcsd/bin/wcanjobs.sh # WCAN Tasks
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
Sean OB_1
Honored Contributor

Re: Getting a message "mesg: not a tty" from cron (root's mail)

Attach those two scripts so we can see what they are doing.
John Palmer
Honored Contributor
Solution

Re: Getting a message "mesg: not a tty" from cron (root's mail)

Even so, something's calling 'mesg' now when it didn't used to. mesg ALWAYS prints that message if it's run as a batch job.

Regards,
John
MAD_2
Super Advisor

Re: Getting a message "mesg: not a tty" from cron (root's mail)

Excellent Jhon, this may be the root of the problem, I was overlooking that. You mentioned something about "mesg"... I'll check on that and be right back! I remember we were having problems with "talk" not working because by default "mesg -n" users profiles are set not to accept messaging, so "mesg -y" was placed in a enviroment file. This may be the root of the problem, I am checking now!
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
John Palmer
Honored Contributor

Re: Getting a message "mesg: not a tty" from cron (root's mail)

I suggest that you replace the call to mesg with:

if [[ -t 1 ]];
then mesg -y
fi

This will only call mesg if standard output (file 1) is associated with a terminal.

Regards,
John
MAD_2
Super Advisor

Re: Getting a message "mesg: not a tty" from cron (root's mail)

Sorry for misspelling your name the first time John, I was rushing it. That seems to have fixed the problem. OK, how can I set talk so that all users may have their "mesg -y" set up automatically? And I mean, not placing it inside each individual's profile?

I see your last reply, is that the answer?

Thanks everyone!
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
John Palmer
Honored Contributor

Re: Getting a message "mesg: not a tty" from cron (root's mail)

If whatever you changed fixed 'talk' then yes, putting mesg inside that if clause will fix your problem.

Regards,
John