shell-init:錯誤檢索當前目錄:getcwd - 通常的修復程序不工作

[英]shell-init: error retrieving current directory: getcwd — The usual fixes do not wor

I have a simple script:


for server in $(~/.ansible/ansible_hosts)
    ssh $server "hostname; readlink /opt/mydir/mylink;"

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: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory


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:

所有目錄都存在。最常見的建議之一是添加cd,cd - 或cd /。添加該步驟時發生的所有情況都是額外的:

chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory


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

我嘗試啟動nfs守護程序,因為我的homedir存在一些混亂,並且如果問題是/ opt,則替換/etc/init.d。沒有不同

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.

這只會是一個煩惱,除了當我嘗試使用ansible playbook而不是簡單的ssh命令時,它對於該服務器來說是失敗的。

Any insights would appreciated.


2 个解决方案



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.

我相信錯誤根本與腳本無關。問題是:當您嘗試運行腳本時,您所在的目錄不再存在。例如,你有兩個終端,cd somedir /在第一個,然后mv somedir / somewhere_else /在第二個終端,然后嘗試在第一個終端運行 - 你會收到此錯誤消息。

At least this was in my case.




You are executing this as a script.. $(~/.ansible/ansible_hosts). The $() means that bash will attempt to execute that script and then output the results.

您正在執行此腳本.. $(〜/ .ansible / ansible_hosts)。 $()表示bash將嘗試執行該腳本,然后輸出結果。

But it's not a script, right? It's a list of hosts!


Just add the word cat and it should work.


for server in $(cat ~/.ansible/ansible_hosts)
    ssh $server "hostname; readlink /opt/mydir/mylink;"



粤ICP备14056181号  © 2014-2021