I want to suppress "no access to tty" error message?
You can check whether stdin
is a terminal before using stty
:
if [[ -t 0 ]]; then stty -echo; fi
Related videos on Youtube
Redson
Updated on September 18, 2022Comments
-
Redson over 1 year
I have a bash script where I use
ssh
to connect to another server and run some commands there. I found some sites that the error (Warning: no access to tty (Bad file descriptor). Thus no job control in this shell.
) is a friendly message but my bash script gets "stuck". No other commands are executed after this message appears. Other forums said to usessh -t
to suppress the message but its not working for me. My code looks something like this:. . . stty -echo sshpass "pwd" ssh -o StrictHostKeyChecking=no [email protected] 'su -lc "rm -rf tmp"' 2>/dev/null stty echo . . .
The reason why I'm using
stty-echo
is because I need to switch users to root and the password is displayed on the terminal (which I don't want). I get the error message (Warning: no access to tty (Bad file descriptor). Thus no job control in this shell.
) after I enter the password for root on the connect server (ip: 1.1.1.1).Any suggestions? Let me know if further explanation is required. Thanks! (My version of bash is GNU bash version 3.2.51(1))
EDIT
The error message I get when removing
2>/dev/null
is:Warning: no access to tty (Bad file descriptor). Thus no job control in this shell. stty: standard input: Invalid argument
-
Redson over 9 years@VolkerSiegel I did strip down the code as much as possible. The error message I'm getting is with this code. I'm unsure of what you mean
-
Volker Siegel over 9 yearsSorry, I meant as much as possible so that the error still occurs. I think the problem will not go away if you remove the ` 2>/dev/null`? But it may hide messages that would help us!
-
Redson over 9 years@VolkerSiegel I will edit the question to give the message I get without
2>/dev/null
-
slm over 9 yearsAdding a
-T
to yourssh
command change things?ssh -To ...
. -
Volker Siegel over 9 yearsHow do you run your script? Do you run it in a terminal?
-
cuonglm over 9 years@Alias: Does it run when you don't use
sshpass
, but usessh -t
? -
Redson over 9 years@slm Still getting the same error
-
Redson over 9 years@VolkerSiegel I am running the script in a terminal
-
Volker Siegel over 9 yearsI think it may depend on what the input of the script is connected to, so what is the exact command?
-
Redson over 9 years@Gnouc Still getting the same error
-
Redson over 9 years@VolkerSiegel Could you clarify? Its a bash script running on the terminal of suse linux enterprise
-
Mark Plotnick over 9 yearsDo you have the access to create an alternative superuser account on the remote, one that doesn't have
csh
ortcsh
as its shell? I'd like to try to eliminate the cause of error messages rather than suppress all remote error messages, because some error messages you may actually want to see. -
Volker Siegel over 9 yearsIt could be that you run it like
./myscript.sh
, orecho foo | myscript.sh | less
, for example? -
Redson over 9 years@MarkPlotnick I'd to eliminate the problem as well. Unfortunately I don't have access to create a superuser. The only superuser is root. What are
csh
ortcsh
? -
Redson over 9 years@VolkerSiegel I run the script like this:
./myscript.sh
-
Mark Plotnick over 9 yearscsh and tcsh are shells, like bash but different. They are mostly used by older BSD systems, and rarely on Linux. The error message Warning: no access to tty (Bad file descriptor) is coming from them. It looks like either root on the remote side has csh or tcsh as its shell, or one of root's init files is running a csh or tcsh script.
-
Mark Plotnick over 9 yearsI don't know of an automated way to translate csh/tcsh init files to bash init files. You need to do it by hand. (Luckily, they all have different names - .login, .tcshrc, .cshrc, .profile, .bash_profile, .bashrc) so you won't need to overwrite anything). Converting them may merit a separate question here if you need assistance beyond the documentation. Then, after that, the command to change change the shell depends on the OS; is the system with tcsh Linux, FreeBSD, Windows running Cygwin, or something else?
-
SHW over 9 yearsIs
/dev/pts
mounted ?
-