rsync 退出并显示消息“stdin is not a tty”

发布于 2024-11-29 08:23:29 字数 428 浏览 1 评论 0原文

我想使用 rsync 到我有 SSH 访问权限的远程服务器。我使用以下命令:

rsync -e 'ssh -p 22222' -rtz --delete content_dir/ [电子邮件受保护]:/home/user/public_html

输入命令后,它会要求输入远程位置的密码。当我输入它时,它会退出并显示消息,

stdin:不是 tty

如何向 rsync 提供密码?当我在 shell 脚本中使用建议的方法时,它也应该有效。

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

rsync -e 'ssh -p 22222' -rtz --delete content_dir/ [email protected]:/home/user/public_html

After entering the command, it asks for the password for the remote location. When I type it, it exits with the message,

stdin: is not a tty

How do I supply the password to rsync? The method suggested should also work when I use it in a shell script.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

还不是爱你 2024-12-06 08:23:29

您需要添加:

[ -z "$PS1" ] &&返回

到位于您的主目录中的 .bashrc 的开头。

You need to add:

[ -z "$PS1" ] && return

to the beginig of .bashrc that is located in your home dir.

请你别敷衍 2024-12-06 08:23:29

正如您自己所说,操作确实发生了,密码正在被接受。

错误消息“stdin:不是 tty”是由于服务器上的启动脚本中的某些内容试图处理仅应在交互式登录时发生的操作(当您使用 ssh 直接连接到服务器时等)。

The password is being accepted here, as you've stated yourself the operation does happen.

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

下壹個目標 2024-12-06 08:23:29

<代码>[ -z "$PS1" ] && return 解决了问题,但它检查提示字符串长度是否为零,如果为零则退出。尽管 $PS1 不会在非交互式 shell 中设置,但 $PS1 的长度为零并不最终意味着该 shell 不是交互式的。

更好的方法是使用 $- 检查 shell 的当前选项。例如 [[ $- != *i* ]] &&返回

[ -z "$PS1" ] && return solves the problem but it checks whether the prompt string length equals to zero and if it does then exits. Although $PS1 will not be set in a non-interactive shell, $PS1 being of zero length doesn't ultimately mean that the shell is not interactive.

Better approach is to check the shell's current options using $-. For example [[ $- != *i* ]] && return.

や三分注定 2024-12-06 08:23:29

如果简单的 return 无法完成这项工作,这里有另一种方法,取自 这篇博客文章

if `tty -s`; then
 mesg n
fi
  • tty -s 检查是否附加了 TTY(-s 告诉它这样做默默地退出并使用适当的返回代码)。 tty 返回附加的 tty(例如“/dev/pts/1”)。这应该比检查某些 shell 变量更安全;)
  • mesg 控制对终端的写入访问(msg n 不允许写入(在我们的例子中不存在的)终端) ,因此需要一个人在场。

在某些系统上(在我的例子中是 Debian Jessie,但也有关于 Ubuntu 的报告) mesg n1中无条件设置~/.bashrc~/.profile。因此,如果它以这种方式存在,那么这可能就是罪魁祸首。

与其他示例一样,您当然可以将其设为单行: [[ $(tty -s ) ]] &&消息n。没有人阻止您将两者结合起来:

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

顺便说一句:根据链接的文章,此片段应该转到您连接的机器的 .bashrc (“远程”) ) – 因此,如果是 johndoe@somehost,则应在 somehost 上的 /home/johndoe/.bashrc 开头应用。就我而言,我只是在“呼叫主机”上应用了此更改后才删除了该消息。

PS:还要检查 .profile 是否有独立的 msg n 命令(在我的例子中确实如此)。如果有,请将其包裹在那里。


1: mesg n 用于防止机器上的其他用户写入您当前的终端设备,这本身是一件好事 - 但对某些人来说没有帮助rsync 作业;)

In case a simple return doesn't do the job, here's another approach taken from this blog article:

if `tty -s`; then
 mesg n
fi
  • tty -s checks if there's a TTY attached (the -s tells it to do so silently and just exit with the appropriate return code). tty returns the tty attached (e.g. "/dev/pts/1"). This should be safer than checking some shell variable ;)
  • mesg controls the write access to your terminal (msg n disallows writing to the (in our case non-existing) terminal), and thus requires one to be present.

On some systems (in my case Debian Jessie, but there are also reports on Ubuntu) mesg n1 is set unconditionally in either ~/.bashrc or ~/.profile. So if it exists that way, this might be the culprit.

As with the other examples, you can of course make that a one-liner: [[ $(tty -s ) ]] && mesg n. And nobody keeps you from combining the two:

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

Btw: According to the linked article, this fragment should go to the .bashrc of the machine you connect to (the "remote") – so if that's johndoe@somehost, this should be applied at the start of /home/johndoe/.bashrc on somehost. In my case I only got rid of the message after having applied this change on the "calling host" as well.

PS: Also check the .profile if it has a stand-alone msg n command (it did in my case). If it does, wrap it there.


1: mesg n is used to prevent other users on the machine writing to your current terminal device, which per se is a good thing – but not helpful for some rsync job ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文