问题描述
我有一个简单的脚本:
#!/bin/bash
for server in $(~/.ansible/ansible_hosts)
do
ssh $server "hostname; readlink /opt/mydir/mylink;"
done
它工作正常 - 程序返回正确的主机名和链接 - 除了我在某些但不是所有服务器上收到以下错误:
It works fine - the program returns the correct hostname and link - except that I get the following error on some but not all of the servers:
shell-init:检索当前目录时出错:getcwd:无法访问父目录:没有那个文件或目录
所有目录都存在.最常见的建议之一是添加 cd、cd - 或 cd/.添加该步骤时发生的所有事情都是额外的:
All the directories exist. One of the most common suggestions has been to add a cd, a cd -, or a cd /. All that happens when that step is added is an additional:
chdir:检索当前目录时出错:getcwd:无法访问父目录:没有那个文件或目录
我尝试启动 nfs 守护进程,因为我的 homedir 存在一些混淆,并替换了/etc/init.d,以防问题出在/opt 上.没有区别
I tried kickstarting the nfs daemon on the off chance that there was some confusion about my homedir and substituted /etc/init.d in case the problem was with /opt. No difference
这只是一个烦恼,除了当我尝试使用 ansible playbook 而不是简单的 ssh 命令时,它对该服务器失败.
This would simply be an annoyance except that when I try to use an ansible playbook instead of a simple ssh command it fails for that server.
如有任何见解,我们将不胜感激.
Any insights would appreciated.
推荐答案
我认为错误与脚本完全无关.问题是:您尝试运行脚本时所在的目录不再存在.例如,您有两个终端,第一个终端是 cd somedir/
,第二个终端是 mv somedir/where_else/
,然后尝试在第一个终端中运行任何内容-您将收到此错误消息.
I believe the error is not related to the script at all. The issue is: the directory at which you are when you try to run the script does not exist anymore. for example you have two terminals, cd somedir/
at the first one then mv somedir/ somewhere_else/
at the second one, then try to run whatsoever in the first terminal - you'll receive this error message.
请注意,即使您重新创建具有相同名称的目录,您也会收到此错误,因为新目录将具有不同的 inode 索引.
Please note you'll get this error even if you re-create directory with the same name because the new directory will have different inode index.
至少在我的情况下是这样.
At least this was in my case.
这篇关于shell-init: error retrieving current directory: getcwd -- 通常的修复不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!