如何解决 Vagrant 中的`ttyname failed: Inproper ioctl for device`?

030*_*030 26 vagrant

使用此代码段时(内联 shell 配置程序):

config.vm.provision "shell" do |s|
  s.inline = <<-SHELL
    <shell code>
  SHELL
end
Run Code Online (Sandbox Code Playgroud)

结果是:

==> default: mesg: 
==> default: ttyname failed
==> default: : 
==> default: Inappropriate ioctl for device
Run Code Online (Sandbox Code Playgroud)

看起来其他人也发现了这个问题。有人知道如何解决吗?

小智 23

1)打开/root/.profile

2)移除进攻线

3)替换为:

tty -s && 消息 n

祝 linuxing 愉快,新年快乐。

乔治·哈特,路易斯安那州立大学

  • 叹。如果只有 ubuntu(和其他?)发行版会在标准的 `/root/.profile` 中解决这个问题......虽然,MacOS 上的 `man tty` 说“-s 选项已被弃用,以支持``test -t 0'' 命令。”,所以更好的替代方法可能是 `test -t 0 &amp;&amp; mesg n` (6认同)
  • 要自动执行此操作,您可以使用 sed -i -e 's/mesg n .*true/tty -s \&amp;\&amp; mesg n/g'` (2认同)

lin*_*des 14

它看起来像这样由默认之间的相互作用引起的流浪配置config.ssh.shellbash -l(其模拟登录shell,从而处理登录相关的配置文件,如.profile)与在一条线上/root/.profileLinux上的至少一些分布(包括文件,例如,在ubuntu/xenial64 vagrant box 中的那个),它有:

mesg n || true
Run Code Online (Sandbox Code Playgroud)

该文件中这一行的更好选择可能是让它说:

test -t 0 && mesg n
Run Code Online (Sandbox Code Playgroud)

...而且,鉴于作为个人流浪用户很难改变,更直接的解决方案是-l从流浪配置中删除该选项,例如使用 (within Vagrantfile):

config.ssh.shell="bash"
Run Code Online (Sandbox Code Playgroud)

(警告:可以想象,这种更改可能会产生潜在的负面影响。不过,对于我来说,它似乎对我很有用,使用一些基本的 shell 配置程序,例如 withapt-get update等等。)


小智 11

我注意到即使此消息显示为错误(红色),脚本也已成功执行!几天后,我看到了一个可能的修复方法,并在 SO 上发布了一个答案。“修复”是:

# Prevent TTY Errors (copied from laravel/homestead: "homestead.rb" file)... By default this is "bash -l".
config.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'"
Run Code Online (Sandbox Code Playgroud)

也许你只是不需要它,但如果它适合你,你可以尝试并使用它。

正如您在上面的注释行中看到的那样 - laravel 团队已阻止“mesg: ttyname failed 不适当的 ioctl for device”。感谢这个!

大多数开发人员都希望在我们进行开发时避免错误/警告,因此看起来我们需要修复(可能的修复)。

重要说明:我没有过多地测试这个解决方案,但该框开始时没有“mesg: ttyname failed 不适合设备的 ioctl”错误!您可以自由尝试,如果遇到任何问题,只需发表评论即可节省其他人的时间!