Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

These two question is driving me crazy and I don't have good expertise of ssh. (but I suspect it is to do with redirection only)

The questions are,

You want to pass multiple lines of input from a file called abc.txt to the ssh command. Complete the command required to do this

$ssh _ _ abc.txt (that is only two characters) (a details explanation would be helpful)

AND

You want to pass multiple lines of input from a file called Remote.txt to ssh but all leading tabs in the subsequent input should be stripped. Complete the command to do this

$ssh _ _ _ Remote.txt

share|improve this question
3  
it seems to be some homework task... Can you explain why u require it exactly.. –  pradeepchhetri Aug 4 '12 at 19:07
    
not exactly home work.. but kind of. it was asked in some interview questions. I know how to it in other way –  Web-E Aug 4 '12 at 19:10
    
what that file is containing ...whether its containing something like user@sshserverip ? –  pradeepchhetri Aug 4 '12 at 19:12
    
not specified in the question.. :( –  Web-E Aug 4 '12 at 19:16
add comment

3 Answers 3

up vote 1 down vote accepted

To pass input from a local file to ssh, you should use input redirection like this:

ssh user@server < abc.txt

Are you sure the _ must be really a single character? In that case this is possible if x is configured in ~/.ssh/config as an alias to some user@host:

ssh x < abc.txt

I cannot answer Q2 because I don't really understand it. I suppose Remote.txt is on the remote.

As per the second question, I suppose Remote.txt is a file on the remote side, in which case the command should be of the form:

ssh user@server "bash < Remote.txt"

...but this does not fit the problem description with _ _ _ and of course to remove the trailing tabs some more would be necessary like:

ssh user@server "bash < <(sed -e 's/^[    ]*//' Remote.txt)"

In other words this does NOT answer the second question. I hope this helps you anyway understanding redirection when used with ssh.

EDIT

After reading the Q another time, since it says "passing multiple lines of input to ssh" suggests that we have to use redirection to ssh again, in which case the file must be local.

ssh user@server < <(sed 's/^[    ]*//' Remote.txt)

But again, I don't think this qualifies as an answer in the form ssh _ _ _ Remote.txt

share|improve this answer
    
you could run: ssh user@server "sed ..." < Remote.txt if the file "Remote.txt" is a local file, although I agree the question is phrased in a way that it's not clear. –  jsbillings Aug 17 '12 at 18:25
    
ssh user@server "bash < Remote.txt" is ssh _ _ _ Remote.txt and ssh user@server "bash < <(sed -e 's/^[ ]*//' Remote.txt)" is ssh _ _ _ _ _ Remote.txt . These command may work but the "question" is still unanswered. –  Ann Jawn Aug 17 '12 at 19:05
    
I had the feeling too.. the question might got altered while flowing down to me. :) –  Web-E Aug 18 '12 at 10:59
add comment

Ans 1.

$ssh user@server cat abc.txt

Ans 2.

$ssh user@server "sed 's/^[    ]//g' Remote.txt"
share|improve this answer
    
Neither of these suggestions do what the OP is asking. –  jsbillings Aug 17 '12 at 18:17
    
Well the question was to fill in the blanks _ and these two command above work perfectly if you ask me. The first blank _ is always user@server, the second _ in the first command has to be exactly one word (or command) which in this case is cat. In the second command the second _ is for sed and third _ is for 's/^[ ]//g'. This sounds more like it unless you can change the question when you sitting in an interview. –  Ann Jawn Aug 17 '12 at 18:57
    
Your first answer is incorrect. The question was to pass input from abc.txt to ssh, and your answer is not doing that. –  janos Aug 18 '12 at 6:55
add comment

For the first part:

$ssh << abc.txt

For the second part:

$ssh <<- remote.txt
share|improve this answer
add comment

protected by slm Mar 30 at 13:10

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.