Unix Shell - scp and stdin

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > February 2007 > scp and stdin





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author scp and stdin
neuneudr@yahoo.fr

2007-02-21, 1:18 pm

Hi,

at the shell prompt (/bin/bash), I'd like to understand what
is happenning in the following case:

1.
.... $ scp temp.png test@192.168.2.121:~/
test@192.168.2.121's password:

OK, this is the behavior expected


2.
$ scp temp.png test@192.168.2.121:~/ < /dev/null
test@192.168.2.121's password:

(I was thinking I'd get back to the shell prompt...)


3.
$ scp temp.png xenaua@192.168.2.121:~/ < /dev/null > /dev/null
xenaua@192.168.2.121's password:


4
....$ scp temp.png xenaua@192.168.2.121:~/ < /dev/null > /dev/null
2&>1
....$

In the three first cases I receive a password prompt.

But in the last case, and it the last case only, I receive the hand
back
immediately (and the copy obviously doesn't happen).

Can someone explain me why things are like that?

neuneudr@yahoo.fr

2007-02-21, 1:18 pm

On Feb 21, 6:31 pm, neune...@yahoo.fr wrote:
> Hi,
>
> at the shell prompt (/bin/bash), I'd like to understand what
> is happenning in the following case:
>
> 1.
> ... $ scp temp.png t...@192.168.2.121:~/
> t...@192.168.2.121's password:
>
> OK, this is the behavior expected
>
> 2.
> $ scp temp.png t...@192.168.2.121:~/ < /dev/null
> t...@192.168.2.121's password:
>
> (I was thinking I'd get back to the shell prompt...)
>
> 3.
> $ scp temp.png xen...@192.168.2.121:~/ < /dev/null > /dev/null
> xen...@192.168.2.121's password:
>
> 4
> ...$ scp temp.png xen...@192.168.2.121:~/ < /dev/null > /dev/null
> 2&>1
> ...$


replying to myself: oops, I meant:

scp temp.png xen...@192.168.2.121:~/ < /dev/null > /dev/null 2>&1

(I mistakingly entered '2&>1' instead of '2>&1').

In any case all commands behave now in the same way: asking for
a password.

How can I do if I want to make sure scp (or any other command)
doesn't 'block' awaiting for input on stdin? (if the command is
failing, I'd rather get the hand back instead of having the command
wait for input on stdin).





Chris F.A. Johnson

2007-02-21, 1:18 pm

On 2007-02-21, neuneudr@yahoo.fr wrote:
> Hi,
>
> at the shell prompt (/bin/bash), I'd like to understand what
> is happenning in the following case:
>
> 1.
> ... $ scp temp.png test@192.168.2.121:~/
> test@192.168.2.121's password:
>
> OK, this is the behavior expected
>
>
> 2.
> $ scp temp.png test@192.168.2.121:~/ < /dev/null
> test@192.168.2.121's password:
>
> (I was thinking I'd get back to the shell prompt...)
>
>
> 3.
> $ scp temp.png xenaua@192.168.2.121:~/ < /dev/null > /dev/null
> xenaua@192.168.2.121's password:
>
>
> 4
> ...$ scp temp.png xenaua@192.168.2.121:~/ < /dev/null > /dev/null
> 2&>1
> ...$
>
> In the three first cases I receive a password prompt.
>
> But in the last case, and it the last case only, I receive the hand
> back
> immediately (and the copy obviously doesn't happen).
>
> Can someone explain me why things are like that?


The password is read from the tty, not stdin.

In no. 4, you didn't receive a prompt because you redirected
stderr, which is where prompts are normally printed.


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Allistar

2007-02-22, 7:15 pm

neuneudr@yahoo.fr wrote:

> On Feb 21, 6:31 pm, neune...@yahoo.fr wrote:
>
> replying to myself: oops, I meant:
>
> scp temp.png xen...@192.168.2.121:~/ < /dev/null > /dev/null 2>&1
>
> (I mistakingly entered '2&>1' instead of '2>&1').
>
> In any case all commands behave now in the same way: asking for
> a password.
>
> How can I do if I want to make sure scp (or any other command)
> doesn't 'block' awaiting for input on stdin? (if the command is
> failing, I'd rather get the hand back instead of having the command
> wait for input on stdin).


I can't answer your specific question, but if you want scp (or ssh) to not
ask for a password you should add your local public key* to the
~/.ssh/authorized_keys2 file on the remote host.

You can generate a public/private pair with the: "ssh-keygen -t rsa"
command, assuming you have the appropriate software installed.

Allistar.
Bin Chen

2007-02-22, 7:15 pm

On 2=D4=C222=C8=D5, =C9=CF=CE=E72=CA=B148=B7=D6, "Chris F.A. Johnson" <cfaj=
ohn...@gmail.com> wrote:
> On 2007-02-21, neune...@yahoo.fr wrote:
>
>
>
>
>
>
>
>
>
>
>
> The password is read from the tty, not stdin.

What is the difference between tty or stdin and which tty the scp use
to input the password?
>
> In no. 4, you didn't receive a prompt because you redirected
> stderr, which is where prompts are normally printed.
>
> --
> Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
> =3D=3D=3D=3D=3D My code in this post, if any, assumes the POSIX locale
> =3D=3D=3D=3D=3D and is released under the GNU General Public Licence



Barry Margolin

2007-02-23, 1:21 am

In article <1172189232.593073.168010@v45g2000cwv.googlegroups.com>,
"Bin Chen" <binary.chen@gmail.com> wrote:
> What is the difference between tty or stdin and which tty the scp use
> to input the password?


/dev/tty is the actual terminal device that you're logged in on. When
you login stdin is connected to /dev/tty, but you can redirect stdin.
That redirection doesn't change the what /dev/tty refers to, so
applications that want to be sure they're talking to the user can open
/dev/tty instead of using stdin.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com