The below command works fine from my localhost and I get the desired output. See below
$ ssh -o ConnectTimeout=7 -o BatchMode=yes root@10.9.60.26 "echo WORKS;exit"
Output:
WORKS
Now, I put this command in a script file test.sh
having sufficient execution privileges
$ cat test.sh
segment=$(ssh -o ConnectTimeout=7 -o BatchMode=yes root@10.9.60.26 "echo WORKS;exit")
echo "SEGMENT $segment"
I don't get the desired output. Infact I get the below error:
$ ./test.sh
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
SEGMENT
I was expecting
SEGMENT WORKS
Now, the Permission denied error goes away but
Can you please suggest what could be the issue ?
ssh -i /<path_to_private_key>
was set is what it was working on local command line but in the script I had to specify the private key explicitly. – Ashar Sep 24 '20 at 08:58bash
scripts. See e.g. https://unix.stackexchange.com/questions/368246/cant-use-alias-in-script-even-if-i-define-it-just-above – Kusalananda Sep 24 '20 at 09:04