Rsync comes out with the message "stdin is not tty"

I want to use rsync for my remote server for which I have SSH access. I use the following command:

rsync -e 'ssh -p 22222' -rtz --delete content_dir/user@example.com: / home / user / public_html

After entering the command, it asks for a password for the remote location. When I print it, it comes out with a message,

stdin: is not tty

How do I provide a password for rsync? The proposed method should also work when I use it in a shell script.

+8
ssh tty rsync
source share
4 answers

You need to add:

[-z "$ PS1"] && & back

to the top of the .bashrc, which is in your home directory.

+18
source share

The password is accepted here, since you stated that the operation is in progress.

The error message "stdin: is not tty" is related to something in running a script on your server trying to process an action that should only happen for interactive logins (when you connect to ssh directly to the server, etc.).

+2
source share

[ -z "$PS1" ] && return solves the problem, but checks to see if the prompt string is zero, and then it ends. Although $ PS1 will not be installed in a non-interactive shell, $ PS1 is of zero length, but does not ultimately mean that the shell is not interactive.

The best approach is to check the current shell parameters using $- . For example [[ $- != *i* ]] && return .

+1
source share

If a simple return does not do the job, here is another approach taken from this blog article :

 if `tty -s`; then mesg n fi 
  • tty -s checks for TTY ( -s tells it to silently do this and simply exit with the appropriate return code). tty returns the tty binding (for example, "/ dev / pts / 1"). This should be safer than checking for some shell variable;)
  • mesg controls write access to your terminal ( msg n prohibits writing to (in our case, nonexistent) terminal), and therefore it is required to be present.

On some systems (in my case, Debian Jessie, but there are also reports on Ubuntu) mesg n 1 is installed unconditionally in either ~/.bashrc or ~/.profile . Therefore, if it exists in this way, it could be a criminal.

As in other examples, you can, of course, do one-line: [[ $(tty -s ) ]] && mesg n . And no one bothers you to combine the two:

 if [[ $(tty -s ) ]]; then mesg n else return fi 

Btw: according to a related article, this snippet should go to the .bashrc device you are connecting to ("remote"), so if it is johndoe@somehost , this should be applied at the beginning of /home/johndoe/.bashrc on somehost . In my case, I just got rid of the message after I applied this change to the “calling host”.

PS: Also check .profile if it has a standalone msg n command (this was in my case). If so, wrap it there.


1: mesg n used so that other users on the machine write to your current terminal device, which in itself is good, but not useful for some rsync job;)

0
source share

All Articles