Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Strange SSH Behavior via system or exec

by choroba (Cardinal)
on Sep 18, 2014 at 15:08 UTC ( [id://1101063]=note: print w/replies, xml ) Need Help??


in reply to Strange SSH Behavior via system or exec

Also try
perl -e 'system("ssh", "-l", "usr", "remotehost", "date")'
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Strange SSH Behavior via system or exec
by cmv (Chaplain) on Sep 18, 2014 at 15:20 UTC
    ++choroba

    That works! Thanks.

    However, shouldn't both work, or am I missing something?

    -Craig

      perl -e 'system("ssh", "-lusr", "remotehost", "date")'
      works but...
      perl -e 'system("ssh", "-l usr", "remotehost", "date")'
      doesn't because it tries to log as user " usr"!
        If this were the case, wouldn't the second case fail as well?
        $ perl -e 'system("ssh -l usr remotehost date")’ # works

      Either you give system a single argument, which is the equivalent of giving that string to the shell to be executed (e.g. /bin/sh -c 'foo bar quz'), or you give system multiple arguments, in which case you are giving that command its argument list directly, without interpretation by the shell. One of the things the shell does is split arguments on whitespace (except Windows), which no longer happens when you give it "-l usr" as a single string. (While some commands may do their own whitespace splitting of their argv, I'd assume that's rare. Except on Windows, hence the need for something like Win32::ShellQuote.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1101063]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2024-04-19 07:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found