[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: ssh and many command line



On Tue, Aug 12, 2003 at 03:21:50PM +0200, Fran?ois Chenais wrote:
> On Tue, 12 Aug 2003 13:50:30 +0100
> Colin Watson <cjwatson@debian.org> wrote:
> > On Tue, Aug 12, 2003 at 01:35:53PM +0200, Fran?ois Chenais wrote:
> > > I try to execute many command on a remote system through ssh but some of those commands fails. What is THE way to execute many commands through ssh ?
> > > 
> > > 
> > > exemples
> > > -----------
> > > 
> > >  [1] ssh root@myhost "cat /etc/passwd | awk -F ':' '{ print $1; }'"
> > > 
> > >      ONLY prints empty lines
> > 
> > You're not quoting correctly. $1 is expanded within "" by the shell on
> > the *local* machine. Try this:
> > 
> >   echo "cat /etc/passwd | awk -F ':' '{ print $1; }'"
> 
> U mean 
> 
> 	"echo \"`cat /etc/passwd | awk -F ':' '{ print $1; }'\""

No, I'm suggesting that you type the command I gave to see how the awk
bit comes out. That's what ssh gets and what it's executing on the
remote machine.

To fix your problem, I would do:

  ssh root@myhost "cat /etc/passwd | awk -F ':' '{ print \$1; }'"

or:

  ssh root@myhost 'cat /etc/passwd | awk -F ":" "{ print \$1; }"'

(Actually I wouldn't use root at all, assuming a machine with shadow
passwords. But anyway.)

Cheers,

-- 
Colin Watson                                  [cjwatson@flatline.org.uk]



Reply to: