1823254 Members
3399 Online
109648 Solutions
New Discussion юеВ

stty: : Unknown error

 
Jeff Crump
Occasional Contributor

stty: : Unknown error

I am using a change management system that allows host-based commands and scripts be called when a file is transferred to a directory location (the commands or script get called).

I am issuing the following commands:

whoami > /home/prandall/cmndslog.txt 2>&1
su - prandall >> /home/prandall/cmndslog.txt 2>&1
echo $SHELL >> /home/prandall/cmndslog.txt 2>&1
uname -a >> /home/prandall/cmndslog.txt 2>&1
whoami >> /home/prandall/cmndslog.txt 2>&1

In the log file I see the following results (the HP system may wrap where the oringal results didn't):

root
stty: : Unknown error
(c)Copyright 1983-2000 Hewlett-Packard Co., All Rights Reserved.
(c)Copyright 1979, 1980, 1983, 1985-1993 The Regents of the Univ. of California
(c)Copyright 1980, 1984, 1986 Novell, Inc.
(c)Copyright 1986-1992 Sun Microsystems, Inc.
(c)Copyright 1985, 1986, 1988 Massachusetts Institute of Technology
(c)Copyright 1989-1993 The Open Software Foundation, Inc.
(c)Copyright 1986 Digital Equipment Corp.
(c)Copyright 1990 Motorola, Inc.
(c)Copyright 1990, 1991, 1992 Cornell University
(c)Copyright 1989-1991 The University of Maryland
(c)Copyright 1988 Carnegie Mellon University
(c)Copyright 1991-2000 Mentat Inc.
(c)Copyright 1996 Morning Star Technologies, Inc.
(c)Copyright 1996 Progressive Systems, Inc.
(c)Copyright 1991-2000 Isogon Corporation, All Rights Reserved.


RESTRICTED RIGHTS LEGEND
Use, duplication, or disclosure by the U.S. Government is subject to
restrictions as set forth in sub-paragraph (c)(1)(ii) of the Rights in
Technical Data and Computer Software clause in DFARS 252.227-7013.

Hewlett-Packard Company
3000 Hanover Street
Palo Alto, CA 94304 U.S.A.

Rights for non-DOD U.S. Government Departments and Agencies are as set
forth in FAR 52.227-19(c)(1,2).
You have mail.
Not a terminal
stty: : Unknown error
stty: : Unknown error

3
1 1 1 1 1 1 1 1 1
logout
/sbin/sh
HP-UX hp9001 B.11.11 U 9000/800 3056282497 unlimited-user license
root

It appears that the su is attempted but then I get some stty errors, funny characters, and the logout.

Can anyone provide some assistance on why I am gettnig the stty errors? If so, how do I resolve them?

Thanks in advance.

Jeff
6 REPLIES 6
Mohanasundaram_1
Honored Contributor

Re: stty: : Unknown error

Hi Jeff,

The .profile of user "prandall" needs to be checked. Since you are calling from a script the message "Not a terminal" is correct.

There may be some customisations in the .profile which is causing this error.

You can also check the forum for Bill Hassell's many reply on this issue. On more than 1 occasion he had explained about stty settings within a script, which I found very useful.

With regards,
Mohan.
Attitude, Not aptitude, determines your altitude
bhavin asokan
Honored Contributor

Re: stty: : Unknown error

hi,

include

export TERM=vt100 in your /etc/profile and .profile of user

regds,
Patrick Wallek
Honored Contributor

Re: stty: : Unknown error

You are doing the 'su - prandall' and redirecting the output to a file. That is the reason you are getting the stty error. It is expecting you to be at a terminal of some sort when doing an su.

Also, the 'su - prandall' will be closed when you go to the next step in the script. It won't do the 'echo $SHELL' within the prandall session, which can be seen by the "logout" message before the /sbin/sh in the output you pasted.
Y.J.JIN
Advisor

Re: stty: : Unknown error

Hi,

su - prandall >> /home/prandall/cmndslog.txt 2>&1

The message with su command.You can check prandall user's .login or .profile files and
Modify about tset and stty.

like this (csh)
eval `tset -s -Q -m ':vt100' `
stty erase "^H" kill "^U" intr "^C" eof "^D" susp "^Z" hupcl ixon ixoff tostop


Ref-URL:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=72142
Jeff Crump
Occasional Contributor

Re: stty: : Unknown error

Patrick:

Interesting. I thought I was just capturing what was being sent to the terminal.

So two follow up questions then:

1) How, within a script, can I get a copy of what is happening when I execute the commands within the script, without having to be at a terminal?

2) How do I maintain the su'd user's profile through the execution of the remainder of the script / commands?

Thanks,

Jeff
Bill Hassell
Honored Contributor

Re: stty: : Unknown error

Let's see if I can help here. First, when you use su - in a script, your script does indeed login and execute all the profiles (/etc/profile and .profile and any related profile/setup scripts). BUT it is not interactive--there is no terminal associated with the script, so anything that tries to set something on the terminal (tput, tabs, tset, ttytype, stty, etc) will fail, complaining about "not a typewriter". That is exactly as expected but probably not what is desired. So, to eliminate these messages, you need to skip terminal commands whenever the script is run in batch mode (ie, cron or at jobs). Here is an example:

if tty -s
then
tabs
fi

or in a simplified form for a single command:

[ tty -s ] && stty erase "^H" kill "^U" intr "^C"

This same technique (if tty -s) must be used in .profile since it has some terminal commands too. Start by rewriting /etc/profile (some other suggestions are here too):

1. Replace:

cat /etc/copyright

with:

if [ tty -s ] && echo "The copyright notice can be read by typing: cat /etc/copyright"

(users will appreciate the reduction of login junk on the screen and your logfile will no longer have all that copyright stuff in it)

2. Replace *ALL* of this code:
# set term if it's not set
if [ "$TERM" = "" -o "$TERM" = "unknown" \
-o "$TERM" = "dialup" -o "$TERM" = "network" ]
then
eval `ttytype -s -a`
fi
export TERM
# set erase to ^H, if ERASE is not set
if [ "$ERASE" = "" ]
then
ERASE="^H"
export ERASE
fi
stty erase $ERASE

with:

if [ tty -s ]
then
eval $(ttytype -s)
sbin/stty erase "^H" kill "^U" intr "^C" eof "^D" -parity ixon ixoff

(NOTE: the use of tset is defintely not recommended--use ttytype in all profiles)

Now, to see every step of a script run in batch mode, the universal way (whether bacth or interactive) is to first exec the script with new I/O and then turn on tracing as in:

exec > /home/prandall/cmndslog.txt 2>&1
set -x

Now the script will send all output to the file in /var/tmp.

As far as maintaining the login environment, you change your execution to:

su - prandall -c /usr/bin/sh /home/prandall/myscript

and you put all your commands to be run as prandall into myscript. The key is that su starts a shell which lasts as long as the shell has something to do, ie, -c myscript.


Bill Hassell, sysadmin