bash script error stty: standard input: Inappropriate ioctl for device
Solution 1
x11vnc expects its standard input to be a terminal, and it changes the terminal mode to avoid echoing the password as you're typing. When standard input isn't a terminal, the stty calls to turn echo off and back on fail, hence the warning that you see.
Expect is indeed a solution. Try this script (untested):
#!/usr/bin/expect -f
spawn x11vnc -storepasswd ~/.vnc/passwd
expect "password:" {send "swordfish" "\r"}
expect "password:" {send "swordfish" "\r"}
expect "Write*\?" {send "y\r"}
Alternatively, if you can, use an authentication method other than RFB (-passwdfile, or an SSL client certificate).
Solution 2
Another option to avoid those warning messages is to execute x11vnc in a pseudo-terminal created by a UNIX command (see Using pseudo-terminals (pty) to control interactive programs). This can be done with the script command or tools such as pdip ("Programmed Dialogue with Interactive Programs").
The warning messages on Mac OS X 10.6.8 for not providing a pseudo-terminal for x11vnc:
# x11vnc 0.9.14
sudo x11vnc -storepasswd ~/.vnc/passwd << ENDDOC
password
password
y
ENDDOC
# Enter VNC password: stty: stdin isn't a terminal
#
# Verify password:
# stty: stdin isn't a terminal
# Write password to ~/.vnc/passwd? [y]/n Password written to: ~/.vnc/passwd
Solutions using the script command:
# GNU script command
sudo script -q -c 'x11vnc -storepasswd ~/.vnc/passwd' <<ENDDOC /dev/null
password
password
y
ENDDOC
# ... or ...
printf '%s\n' 'password' 'password' 'y' |
sudo script -q -c 'x11vnc -storepasswd ~/.vnc/passwd' /dev/null
# FreeBSD script command
sudo script -q /dev/null x11vnc -storepasswd ~/.vnc/passwd <<ENDDOC
password
password
y
ENDDOC
Solution 3
Sudo has an option -S that allows it to read the passwd from STDIN.
[[email protected] ~]$ tail -1 /etc/shadow
tail: cannot open `/etc/shadow' for reading: Permission denied
[[email protected] ~]$ echo '[email protected]!' | sudo -S tail -1 /etc/shadow
nfsnobody:!!:15891::::::
Here is an example script to demonstrate the process:
#!/bin/bash
function hr {
perl -e 'print "-" x 80, "\n";'
}
hr
read -p "Please enter your sudo password: " -s sudopasswd
echo
hr
echo "-sudo run: tail -1 /etc/shadow"
tail -1 /etc/shadow
hr
echo "+sudo run: tail -1 /etc/shadow"
echo "$sudopasswd" | sudo -S tail -1 /etc/shadow
hr
echo "-sudo run: ls -la /root/"
ls -la /root/
hr
echo "+sudo run: ls -la /root/"
echo "$sudopasswd" | sudo -S ls -la /root/
hr
Your script, would simply need to do something like:
read -p "Please enter your sudo password: " -s sudopasswd
echo "$sudopasswd" | sudo -S x11vnc -storepasswd ~/.vnc/passwd
This would allow you to use sudo commands in your script without having to hardcode a password.
Alternatively, you could add your user, or a subset of users, the capability to run x11vnc with sudo, without a password, but adding a line like this to /etc/sudoers:
user ALL=(root) NOPASSWD: /path/to/x11vnc
Or create a vncusers group, add users to that group, and add the following to /etc/sudoers:
%vncusers ALL=(root) NOPASSWD: /path/to/x11vnc
Related videos on Youtube
Jarek
You may be interested in the story of SE moderator Monica Cellio and how she was unfairly treated by the corporate management of this site. More info here. An update is available. Let's hope we can cultivate a more fair environment for content creators and moderators going forward.
Updated on September 18, 2022Comments
-
Jarek 4 monthsI'm using here-documents in a bash script to automate installation and setup where a password is required many times. I enter the password once and the script passes it to the various commands. In most instances the here-document approach handles this fine. However, in one case I get this error:
Enter VNC password: stty: standard input: Inappropriate ioctl for device Verify password: stty: standard input: Inappropriate ioctl for devicePlease notice that this error message is from
x11vnc -storepassword(not fromsudo.)My problem is related to
x11vnc -storepasswdand here's my code:sudo x11vnc -storepasswd ~/.vnc/passwd << ENDDOC password password y ENDDOCThat obviously (from the error) does not work. I would appreciate a working example of how to implement
sudo x11vnc -storepasswd ~/.vnc/passwdin a script.In case it helps, the prompts look like this:
Enter VNC password:
Verify password:
Write password to /home/user/.vnc/passwd? [y]/n nWill using
expectbe a better solution? If so, how would I use it in this case? (I have never usedexpectbefore but I have looked at a lot of examples since posting this question and I cannot getexpectto work on my own.) -
Jarek over 9 yearsThanks. However, the error is not coming fromsudoit is coming fromx11vnc -storepassword. -
Jarek over 9 yearsThanks. However, the error is not coming fromsudoit is coming fromx11vnc -storepassword. I've been trying variousexpectapproaches and I can't seem to get it right. An example usingexpectto enter a password forx11vnc -storepasswordwould be greatly appreciated. I'll update my question to avoid further confusion. -
Gilles 'SO- stop being evil' over 9 years@MountainX Right, sorry, I'd misread the question. Here's an expect script (completely untested). -
Jarek over 9 yearsThank you. Your untested script gave me a few additional clues, but ultimately it also does not run without errors. The error is simplyEnter VNC password: usage: send [args] stringon the lineexpect "password:" {send "swordfish" "\r"}. I'm not sure how to fix that. Expect seems to be a very picky tool because I've been fooling with this particular problem for hours without working results yet. -
Jarek over 9 yearsThe error (above comment) was coming fromsend "swordfish" "\r"and it was resolved bysend "swordfish\r". However, the solution still doesn't work. No password is written to ~/.vnc/passwd. I am still clueless as to why. As I said, I've been seeing this result in spite of trying everything I can think of so far. -
Jarek over 9 yearsBTW, the same commands used in yourexpectsolution work when entered manually. They do not work in thisexpectscript or any variation of it that I have tried so far. -
alper over 2 yearsI am getting following error:spawn: command not found, line 3: expect: command not foundshould I put it into.zshrcfile? -
Gilles 'SO- stop being evil' over 2 years@alper This an an expect script, not a shell script. You need to write the code to a file, make it executable, and execute it. And you need to installexpect.