-1

How does one verify that linux command is successfully executed over the ssh server? See the following example

ssh -qX 10.10.1.123 chmod -R 755 someDir/

I know that using the return code (0 or 1) method works but there are instances where the above command executes but the permissions do NOT get changed. Is there a better way to verify whether it executed successfully and permissions are changed accordingly?

Amp
  • 111
  • 5
  • Does `chmod` itself have the same problem "where the above command executes but the permissions do NOT get changed", without it being reflected in exit status? – Charles Duffy Oct 14 '21 at 13:33
  • ...to be clear: If `chmod` itself still has that problem, I don't think this has any reason to be a question about `ssh`; all you care about is detecting whether the chmod problem happened, and whether it's local or remote is immaterial. – Charles Duffy Oct 14 '21 at 13:34
  • (btw, why `ssh -X`? You aren't running a GUI application here) – Charles Duffy Oct 14 '21 at 13:35
  • 2
    What are the scenarios where `ssh` returns a success status even tough the command failed? I can't think of any. – tripleee Oct 14 '21 at 13:35

1 Answers1

1

There's no generic answer, because there's no generic problem. ssh does not return success to the caller unless the remote child gave a successful result.

For the specific problem, assuming your remote machine has a version of chmod that can incorrectly return unwarranted successful exit statuses, one might use:

if [[ $(ssh 10.10.1.123 'find someDir/ ! -perm 755 -print -quit') ]]; then
  echo "At least one file under someDir did not have its permissions changed to 755" >&2
fi
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441