Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chdir: error retrieving current directory: getcwd: cannot access parent directories #36

Closed
arozehnal opened this issue Mar 2, 2024 · 8 comments

Comments

@arozehnal
Copy link

arozehnal commented Mar 2, 2024

I have two logins roze and roze2.
On target host (kom) sudoers with such entry.
roze,roze2 ALL=(ALL) NOPASSWD: ALL

I can run right on target host simple:
/tmp: sudo -u roze touch b2

ls -l b2
-rw-r----- 1 roze xxx 0 2 bře 23:23 b # OK

but when I run
gossh command kom -U roze -s -e "cd /tmp; touch /tmp/pokus " -v -p ....

[DEBUG] 2024-03-02 23:39:56.182174 kom: execute command 'sudo -u roze -H bash -c ' cd /tmp; touch /tmp/pokus'' success, output: shell-init: chyba při zjišťování současného adresáře: getcwd: rodičovské adresáře nejsou přístupné: Přístupová práva souboru neumožňují provádět zadanou činnost.
chdir: error retrieving current directory: getcwd: cannot access parent directories: The file access permissions do not allow the specified action.

kom 2024-03-02 23:39:56.182553 | SUCCESS >>
shell-init: chyba při zjišťování současného adresáře: getcwd: rodičovské adresáře nejsou přístupné: Přístupová práva souboru neumožňují provádět zadanou činnost.
chdir: error retrieving current directory: getcwd: cannot access parent directories: The file access permissions do not allow the specified action.

[INFO] 2024-03-02 23:39:56.182597 success count: 1, failed count: 0, elapsed: 0.43s

/tmp/pokus was not created
how is it possible that failed count is 0 ??

================
AIX 7.2
gossh version
gitVersion: 92e3206
gitCommit: 92e3206
gitTreeState: clean
buildDate: 2024-02-25T11:23:47Z
goVersion: go1.20.2
compiler: gc
platform: aix/ppc64

@windvalley
Copy link
Owner

@arozehnal The reason is that the last command in the command sequence, touch /tmp/pokus, has a return code of 0, which indicates success. You can replace the commands as follows:
"cd /tmp && touch /tmp/pokus" or "set -e; cd /tmp; touch /tmp/pokus"

@arozehnal
Copy link
Author

arozehnal commented Mar 3, 2024

OK, the command sequence, that seems like a reasonable explanation at first glance
but the reality is different :-(

First... whichever of the two I run:
"set -e; cd /tmp; touch /tmp/pokus"
"cd /tmp && touch /tmp/pokus"

the result is still the same:
[INFO] 2024-03-03 14:16:33.272838 success count: 1, failed count: 0, elapsed: 0.31s

and the file is still not created

second) the cause is probably hidden behind the source of the message
chdir: error retrieving current directory: getcwd: cannot access parent directories:
which current/parent dir is this?

========================

Debug message:
execute command 'sudo -u roze -H bash -c 'cd /tmp && touch /tmp/pokus'' success, output: shell-init:
indicates the use of the '-H bash' option
Wwhat is this option? I don't see it in the gossh documentation.

My default shell is 'ksh' can't too be causing the problem?

@arozehnal arozehnal reopened this Mar 3, 2024
@arozehnal
Copy link
Author

arozehnal commented Mar 3, 2024

I tried both variants of the chained commands by changing my ksh to bash before running gossh on the source, respectively I set bash as default to both logins roze and roze2 on the target server.

The result is still the same though. :-(

===================

simple test chained commands
bash-5.1$ ls a*
a # OK, just 'a' exists

bash-5.1$ ls a aa; echo $?
aa not found
a
2 # as expected

bash-5.1$ cat a|wc -l; echo $?
0
0 # as expected

bash-5.1$ cat aa|wc -l; echo $?
cat: cannot open aa # as expected
0
0 # hmm, strange

set -o pipefail; cat aa|wc -l; echo $?
cat: cannot open aa # as expected
0 #
2 # finally as expected

and the worst news at the end...
AIX ksh does not support 'set pipefail'

@windvalley
Copy link
Owner

Sorry, I can't reproduce the issue you are encountering. I don't have an AIX environment, but I set up a ksh environment on my virtual machine(CentOS7.9) as remote host and mocked the users(using ksh) and actions as yours, then executed the command like gossh command kom -U roze -s -e "cd /tmp; touch /tmp/pokus " -v -p ...., but everything is ok, no warnings, no errors, and the file /tmp/pokus was successfully created.

For you saying 'AIX ksh does not support set pipefail', if your AIX server has bash installed, there shouldn't be a problem with it, coz as you know gossh use bash to run commands.

@arozehnal
Copy link
Author

I'm not surprised by the different behaviour of AIX ksh from other shells, I've been living with it for 20 years :-(.
AIX is quite exotic and closed in some cases. And their native KSH is an exemplary case.
Unfortunately, I'm working on a project that has been in development for over 20 years, and the primary shell in it is that basic AIX ksh.

I really like gossh and would like to use them, I understand that it's hard to give support for what I don't have access to.
But I still think that maybe in this case there might be a problem with the parrent directory rights.
It behaves pretty much like that demo of chained commands in bash with/without using pipefail.

I run gossh from the home directory of roze2 (/home/roze2), on the target and I want to create a file in /tmp on the target..
I run gossh on the source as roze, but on the target I execute the action as roze2.
I have three questions:

  1. the problem is on source or target server?
  2. is the shell problem of roze or roze2
  3. where is the source of the message:
    chdir: error retrieving current directory: getcwd: cannot access parent directories:
    Which directory is it? /home /tmp ...?

It is not clear from the gossh debug module.

So far I have tried changing the default shell for both roze and roze2 on the target to bash but the result is still the same.

@windvalley
Copy link
Owner

windvalley commented Mar 4, 2024

  1. on target server
  2. not sure
  3. not sure. I guess it may be the $HOME of roze2 on target server if the raw command is like sudo -u roze2 -H bash -c ''.

Please list results of the followings commands on target server:

  1. ls -ld /tmp
  2. ls -ld xxx(home of roze)
  3. ls -ld xxx(home of roze2)

In addition, login the target server with 'roze', then execute sudo -u roze2 -H bash -c 'cd /tmp; touch /tmp/pokus'. Can it run successfully? If not, paste the outputs.

@arozehnal
Copy link
Author

I have only good news :-)

  • the error message "chdir: error retrieving current directory: getcwd:" has stopped appearing
  • /tmp/pokus was created with the correct attributes
  • incorrect initial command of the chained commands, it is correctly detected and notified
  • all this using by default AIX ksh and without set pipefail

I just don't know what caused the problems so far. When trying to change the default shell, I did the straightforward thing of canceling the roze2 login and then setting it up with a regular AIX routine. So probably something wrong when creating the user (?).

Thank you very much for your patience and willingness to help.

One last question (I promise this is the last question for this week :-) :-))
I will run using gossh scripts on about 80-100 target servers, the scripts have short outputs on STDOUT, maximum 50-100 lines of text.
Is there any reason to use "-c int"? How many concurrent sessions would you choose?

@windvalley
Copy link
Owner

windvalley commented Mar 5, 2024

@arozehnal If you do not use the -c flag, it will SSH all servers serially, which is less efficient. As for how many concurrent sessions to set, it really depends. If you have 4Cores and 8GB of available resources(source server), I think setting it to 100 concurrent sessions is not a problem. Of course, I still recommend that you test and find the most efficient number based on your actual conditions:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants