Operating System - HP-UX
1833300 Members
2901 Online
110051 Solutions
New Discussion

stty not a typewriter message

 
SOLVED
Go to solution
KPS
Super Advisor

stty not a typewriter message

Hi,

A .profile for a certain user on our system has been recently changed to reference some stty commands being set such as:

stty erase "^H" kill "^U" intr "^C" eof "^D"

Our batch processes on our system run as this user by su - and these processes then get run as this user. These are now erroring out saying: "stty not a typewriter." They have worked fine prior to this. Could this problem be related to the stty commands being set in the profile of this user?

Would anyone have any tips for this situation?

Thanks,
-Ken
3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: stty not a typewriter message

This is perfectly normal and is why I never su - user anything but only su user and have both the user's .profile and the batch comand source a file that sets and exports and needed environment variable via the . (dot) operator.

In your case, the workaround is to surround any commands in .profile that expect an interactive environment (ie stdin, file descriptor 0, is a terminal) with
if [[ -t 0 ]]
then
stty ..
tabs ..
tset ...
fi
If it ain't broke, I can fix that.
Steven E. Protter
Exalted Contributor

Re: stty not a typewriter message

Batch processes will run into this from time to time. The reason is that terminal and stty settings are not set.

This command caused the issue whether this is a batch or interactive shell issue:

stty erase "^H" kill "^U" intr "^C" eof "^D"

I would back this change out or set stty settings for your users to the way they need to be.

In general, when I see this in batch, I ignore it except for oracle which sometimes refuses to tolerate certain stty settings when an application shells to the OS.

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: stty not a typewriter message

Clay described the problem. When you run a batch process (using cron, at or through remsh, etc) the script does not login (and consequently has no terminal). Tyerefore, every command to control a terminal such as stty, tabs, clear, tput, ttytype, tset, etc) will fail with the "typewriter" message. So your batch jobs must exclude such commands.

However, su - user will perform a pseudo-login by running /etc/profile and .profile and these often (and should) contain terminal commands. As Clay mentioned, you can drop the - option to just switch users but then none of the /etc/profile and .profile settings will occur...you have to explicitly set these in your script.

Or you can exclude them in /etc/profile and .profile (so you can indeed use su - user) and the errors go away. I prefer fixing /etc/profile and .profile because changes made in those scripts are occasionally made and sysadmins may forget to update the application scripts. There are several ways to detect if the script is running without a terminal. Here is another way using tty:

if tty -s
then
stty ...
tabs ...
fi

It is a good idea to collect all the terminal commands in a script and group them together so there will only be 1 test needed for a terminal connection.


Bill Hassell, sysadmin