Operating System - HP-UX
1855357 Members
3759 Online
104110 Solutions
New Discussion

Re: cron email message failure

 
Mark McCurdy
Occasional Advisor

cron email message failure

Hi All,

I was attempting to clean-up cron generated email messages. I was receiving the "stty::Not a typewriter" message. We don't have a terminal attached. I found the following code to eliminate the messages, but I've discovered that I can no longer receive any messages from the system. I ran the same script that worked before I modified the /etc/profile file and I can't receive the email message. The code I added to the /etc/profile file is as follows:

==begin

tty > /dev/null
rc=$?

if [ $rc -eq 0 ]
then
stty erase "^H" kill "^U" intr "^C" eof "^D" susp "^Z"
[[ $TERM = vt220 ]] && stty erase "^?"
[[ $TERM = vt200 ]] && stty erase "^?"
stty hupcl ixon ixoff
tabs
fi
==end

I put the original /etc/profile file back, but still can't receive email. Any ideas?

Thanks,
Mark
6 REPLIES 6
Steven E. Protter
Exalted Contributor

Re: cron email message failure

cron jobs get NO environment at all.

not from /etc/profile
not from .profile

set up the TERM variable in the job and it will stop with the typewriter message.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Mark McCurdy
Occasional Advisor

Re: cron email message failure

So, the above modification to /etc/profile should not have caused any problems. And, removing that section should be fine. Or, do I have to set stty back to the default? I'm not familiar with &@91 syntax. I'll have to investigate the TERM variable further. Thanks
Sundar_7
Honored Contributor

Re: cron email message failure

Mark,

A better way to check if the process is attached to a terminal or not is to check for the existence of the filedes 1 (i.e stdout)

if [ -t 1 ]
then
stty erase "^H" kill "^U" intr "^C" eof "^D" susp "^Z"
[[ $TERM = vt220 ]] && stty erase "^?"
[[ $TERM = vt200 ]] && stty erase "^?"
stty hupcl ixon ixoff
tabs
else
# Not attached to a terminal
# Skip the stty commands
:
fi

You donâ t need an else section in there, but I added just to demonstrate.

But as noted above, cron jobs donâ t use /etc/profile or any of the login initialization files unless otherwise referred explicitly (like if your job executes su - or sources . /etc/profile with in the script).

- Sun
Learn What to do ,How to do and more importantly When to do ?
Steven E. Protter
Exalted Contributor

Re: cron email message failure

If the script is run by cron a change in /etc/profile should not effect the script.

Unless, the script has a . /etc/profile at the top.

Thats probably a bad idea but could set up a scanario under which /etc/profile does effect script behavior.

Also the /usr/bin/su - usernamne -c will pick up the environment of the user in the username section.

Seems there may be something wrong with the sendmail setup.

try this:

sendmail -v -d8.99 -d38.99 someone@your.net

type some text

.


This will get you great diagnositcs and point to any sendmail configuration errors or eliminate that as a possibility.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Bill Hassell
Honored Contributor

Re: cron email message failure

You are getting the "not a typewriter" messages because your script is probably doing an su - . In this case, su - will go through a normal login procedure but because there is no 'real' terminal, all commands in /etc/profile and .profile will be run, which is why copyright and motd messages also show up in cron email. It's always a good idea to protect terminal commands for all login profiles that may be used in cron. The terminal commands that are commonly found in profiles are:

tty
ttytype
tset
stty
tabs
tput

One way to handle this is to put all the terminal-specific code in a seperate file, things like setting DISPLAY. You can then use one several interactive terminal tests to run the script:

if echo $- | grep i
...

if [ -t 1 ]
...

If tty -s
...

Note that setting TERM=vt220 is not a good idea as it forces terminal-aware code to output only one set of strings. The correct way is to set the terminal using ttytype:

eval $(ttytype -s)


Bill Hassell, sysadmin
Prashant Zanwar_4
Respected Contributor

Re: cron email message failure

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=114552

This thread in which some of the guys here have replied has good assistance.
Hope it helps
Prashant
"Intellect distinguishes between the possible and the impossible; reason distinguishes between the sensible and the senseless. Even the possible can be senseless."