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

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


I have a simple script:

我有一個簡單的腳本:

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

shell-init:檢索當前目錄時出錯:getcwd:無法訪問父目錄:沒有這樣的文件或目錄

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

chdir:檢索當前目錄時出錯:getcwd:無法訪問父目錄:沒有這樣的文件或目錄

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 个解决方案

#1


15  

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.

至少這是我的情況。

#2


0  

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.

只需添加單詞cat就可以了。

#!/bin/bash
for server in $(cat ~/.ansible/ansible_hosts)
do
    ssh $server "hostname; readlink /opt/mydir/mylink;"
done

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2015/04/01/72f5ef5fd461f3001487886bee30871a.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com