Shell init ошибка получения текущей директории getcwd

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

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: 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

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.

Столкнулся с проблемой:

shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory

или

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

или

sh: 0: getcwd() failed: No such file or directory

Попробовал перейти в другую папку:

# cd /home/captain/some_dir

Получил ошибку:

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

Так же, попробовал использовать TAB для автоподстановки пути:

# cd /hsymlink-hook: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory

И так, данная проблема возникает когда команда пробует выполнять что-то уже не из существующей папки. По этому, решение очень простое — нужно перейти в любой другой существующий каталог

# cd ~

и

# pwd

/home/captain

или:

# cd $(pwd)

Смотрим теперь:

# ls -l /home/captain/some_dir

ls: cannot access /home/captain/some_dir: No such file or directory

Вот и все, я завершаю свою тему «Ошибка shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory».

  • Архив новостей

    Архив новостей

  • Свежие записи

    • Pull/Push AWS ECR образов через AWS Route53 CNAME
      17.11.2021
    • openpgp: signature made by unknown entity в Terraform
      09.11.2021
    • Установка Terraformer в Unix/Linux
      31.05.2021
    • Установка ArgoCD в Unix/Linux
      06.01.2021
    • Установка tfswitch в Unix/Linux
      08.12.2020
  • Мета

    • Войти
    • Лента записей
    • Лента комментариев
    • WordPress.org


Linux

  • 15.04.2016
  • 26 112
  • 2
  • 18.03.2019
  • 46
  • 46
  • 0

Исправляем ошибку: sh: 0: getcwd() failed: No such file or directory

  • Содержание статьи
    • Описание
    • Комментарии к статье ( 2 шт )
    • Добавить комментарий

Если при работе в ОС Linux вы получаете ошибку «getcwd() failed: No such file or directory», то в данной статье пойдет речь о причинах.

Описание

Полностью текст ошибки выглядит вот так:

sh: 0: getcwd() failed: No such file or directory

Или же

shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory

Это скорей всего происходит из-за того, что Вы пытаетесь запустить команду(ы) из директории, которой больше не существует (была удалена). Чтобы проблема исчезла, необходимо просто перейти в какой-либо существующий каталог. Например в корень файловой системы:

cd /

Describe the bug

When direnv is loading a .envrc file, it prints these messages and does not load the .envrc file

shell-init: error retrieving current directory: getcwd: cannot access parent directories: Bad file descriptor
pushd: error retrieving current directory: getcwd: cannot access parent directories: Undefined error: 0
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: Undefined error: 0

To Reproduce
Steps to reproduce the behavior:

I’ve simplified my zsh configs down to the following:

.zshrc

eval "$(direnv hook zsh)"

.zshenv

path=("/usr/local/bin" $path)  # this is where homebrew installs direnv
export -U PATH

~/workspace/.envrc

export AWS_PROFILE=development

Install direnv

Then start a new shell and cd into ~/workspace and permit the envrc file to be loaded

$ cd ~/workspace
$ direnv allow

Expected behavior

I expect direnv to set AWS_PROFILE with the value development, but I see AWS_PROFILE is still unset and there are errors printed to the console, described above.

Environment

  • OS: macOS Big Sur, and also macOS 10.15.7
  • Shell: zsh 5.8 (x86_64-apple-darwin20.1.0) from homebrew, and also zsh 5.8 (x86_64-apple-darwin20.0) stock with macOS
  • Direnv version: 2.24.0 from homebrew, and also 2.23.1 (built from source) and 2.23.0 (built from source) and 2.22.0 (built from source)

Additional context

I have been using direnv on this same machine for some time, I’m not sure exactly what broke it. I thought at first it was one of my configs but after stripping away all my configs, removing and re-installing direnv, and still running into this issue I fear I’m in above my head.

I have isolated the messages to be coming from the shell hook, which on my machine is defined as

$ direnv hook zsh
_direnv_hook() {
  trap -- '' SIGINT;
  eval "$("/usr/local/bin/direnv" export zsh)";
  trap - SIGINT;
}
typeset -ag precmd_functions;
if [[ -z ${precmd_functions[(r)_direnv_hook]} ]]; then
  precmd_functions=( _direnv_hook ${precmd_functions[@]} )
fi
typeset -ag chpwd_functions;
if [[ -z ${chpwd_functions[(r)_direnv_hook]} ]]; then
  chpwd_functions=( _direnv_hook ${chpwd_functions[@]} )
fi

I’m not familiar enough with zsh to know what the hooks are doing, however when I run direnv export zsh manually I get no output 🤔 seems like nothing would be evald then

Here’s an error reported by one of our regular reader Anu. She says, cluster-fork  w command ends up with an error “shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory“.

Here’s the complete snapshot of the error:

$cluster-fork w
compute-0-0: shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
down
compute-0-1: shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory

shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory

Solution:

This error mostly occurs when the directory in which this command was executed does not exist anymore. For example, assume that you had changed directory to 'test' and issued cluster-fork command. During the execution of cluster-fork, if the directory test was removed (may be a program that regularly cleans disk space or mistakenly deleted from a different terminal), then 'getcwd' will not be able to return the current working directory. Hence, cluster-fork will return an error “getcwd: cannot access parent directories: No such file or directory”.

To fix this error, one has to just get out of that non-existent directory. Usually by issuing 'cd' command to get to the home directory and execute cluster-fork command.

Note:

Using cd .. will not work and you will still end up with the same error message.

Понравилась статья? Поделить с друзьями:
  • Sheetcam ошибка достигнут предел оценочного периода
  • Sheep eat grass где ошибка
  • She watches tv in free time где ошибка
  • She travel every summer исправьте ошибки
  • She speak french very well найдите ошибки