Hi all,

I am really new in bash scripting and I can't even make simple tasks

What I am trying to do is executing a command (ls -l for this example), over a double leap ssh.

#!/bin/bash
ssh -T myuser@entrypoint ssh -T myuser@targetpc<<EOI
 ls -ltr .
exit
EOI

I did the following script before and it works, but since I need a double leap it is not useful at all

#!/bin/bash
ssh -T myuser@targetpc<<EOI
 ls -ltr .
exit
EOI

My naive assumption was that it would be just adding another ssh to the line

Thank you!

What is the problem?!
Any errors you're getting..

Sorry, I should have posted the errors too

I am promted for the entrypoint password, and after entering successfully this is what I get

Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-with-mic,password).

Have you setup passwordless ssh between entry-point and target machines?
If not I'm surprised that you got any output as I would expect that when ssh -T myuser@targetpc is executed it hangs instead of giving permission denied. But then the IO redirection with SSH is always shaky/complex to understand.
Perhaps first ssh didn't create any input stream when it executed second ssh, which in turn wanted the password. And thus the second one executed immediately without password and failed. But this is of course guess..

What I would usually do while dealing with remote machines is to
- create a one liner script, which does what I want then
---- The script ensures that it puts all output in some "output file".
- copy this (via rcp/scp) to the remote machine
- execute the script with ssh
- fetch the "output file", parse and find the result.

This is purely for reliability and working around the thousand issues that ssh has with IO redirection.

In your case if you do this it would surely help to point out where the problem is. You'll get better understanding of the flow and which command is doing what. (of course I assume that you'll make your one liner script write enough log messages to output file_:) )

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.