Hi
I am sure the answer here is really easy but i am stuck!
# mount | grep data | awk '{print$1,$2,$3}'
gives me the info i require locally, however i need to execute this over about 1000 hosts so i run things remotely using ssh something like
# MOUNTER=`ssh $i 'mount | grep data | awk '{print$1,$2,$3}''`
however this fails as at the end of the line there are 2 ticks eg ' together -
Can anyone offer me some syntax help please?
thanks
On Oct 26, 2007, at 6:28, Tom Brown wrote:
I am sure the answer here is really easy but i am stuck!
Getting the quoting right for remote commands in the shell is never an easy thing :-).
# mount | grep data | awk '{print$1,$2,$3}'
gives me the info i require locally, however i need to execute this over about 1000 hosts so i run things remotely using ssh something like
# MOUNTER=`ssh $i 'mount | grep data | awk '{print$1,$2,$3}''`
however this fails as at the end of the line there are 2 ticks eg ' together -
Can anyone offer me some syntax help please?
I can usually get this to work with some trial an error by doubling up quotes and using backslahes but it's a frustrating experience. Instead, I use a different technique: I put a script in a network accessible place (i.e., a common NFS mount) and then use ssh to execute that script.
Alfred
How about # MOUNTER=`ssh $i "mount | grep data | awk '{print $1,$2,$3}'"`
alas no
MOUNTER=`ssh $i 'mount | grep data | awk "{print $1, $2, $3}"'`
results in
awk: {print , , } awk: ^ syntax error awk: {print , , } awk: ^ syntax error awk: {print , , } awk: ^ syntax error awk: cmd. line:1: {print , , } awk: cmd. line:1: ^ unexpected newline or end of string
How about # MOUNTER=`ssh $i "mount | grep data | awk '{print $1,$2,$3}'"`
alas no
MOUNTER=`ssh $i 'mount | grep data | awk "{print $1, $2, $3}"'`
results in
awk: {print , , } awk: ^ syntax error awk: {print , , } awk: ^ syntax error awk: {print , , } awk: ^ syntax error awk: cmd. line:1: {print , , } awk: cmd. line:1: ^ unexpected newline or end of string
oops and actually doing what you asked results in the same
MOUNTER=`ssh $i "mount | grep data | awk '{print $1, $2, $3}'"`
awk: {print , , } awk: ^ syntax error awk: {print , , } awk: ^ syntax error awk: {print , , } awk: ^ syntax error awk: cmd. line:1: {print , , } awk: cmd. line:1: ^ unexpected newline or end of string
Tom Brown wrote:
How about # MOUNTER=`ssh $i "mount | grep data | awk '{print $1,$2,$3}'"`
alas no
MOUNTER=`ssh $i 'mount | grep data | awk "{print $1, $2, $3}"'`
results in
awk: {print , , } awk: ^ syntax error awk: {print , , } awk: ^ syntax error awk: {print , , } awk: ^ syntax error awk: cmd. line:1: {print , , } awk: cmd. line:1: ^ unexpected newline or end of string
Sorry,
MOUNTER=`ssh $i 'mount | grep data | awk "{print \$1,\$2,\$3}"'`
Anup Shukla wrote:
Tom Brown wrote:
How about # MOUNTER=`ssh $i "mount | grep data | awk '{print $1,$2,$3}'"`
alas no
MOUNTER=`ssh $i 'mount | grep data | awk "{print $1, $2, $3}"'`
results in
awk: {print , , } awk: ^ syntax error awk: {print , , } awk: ^ syntax error awk: {print , , } awk: ^ syntax error awk: cmd. line:1: {print , , } awk: cmd. line:1: ^ unexpected newline or end of string
Sorry,
MOUNTER=`ssh $i 'mount | grep data | awk "{print \$1,\$2,\$3}"'`
Correction. MOUNTER=`ssh $i "mount | grep data | awk '{print \$1,\$2,\$3}'"`
This is what i tried and worked for me.
Regards, A.S
On Fri, Oct 26, 2007 at 06:56:05PM +0800, Anup Shukla wrote:
MOUNTER=`ssh $i "mount | grep data | awk '{print \$1,\$2,\$3}'"`
This is what i tried and worked for me.
Why not be simpler, run the "mount" on the remote machine but the grep and awk on the local machine; no quoting issue at all then
MOUNTER=`ssh $i mount | grep data | awk '{print $1,$2,$3}'`
(more network data, less remote processing)
On Fri, Oct 26, 2007 at 11:28:37AM +0100, Tom Brown wrote:
Hi
I am sure the answer here is really easy but i am stuck!
# mount | grep data | awk '{print$1,$2,$3}'
gives me the info i require locally, however i need to execute this over about 1000 hosts so i run things remotely using ssh something like
# MOUNTER=`ssh $i 'mount | grep data | awk '{print$1,$2,$3}''`
however this fails as at the end of the line there are 2 ticks eg ' together
Can anyone offer me some syntax help please?
Well, you don't need to run the grep and awk on the other side:
MOUNTER=`ssh $i mount | awk '/data/{print $1,$2,$3}'`
But you can live without the call to mount, too: MOUNTER=`ssh $i awk "'/data/{print $1,$2,$3}'" /etc/mtab`
On Fri, Oct 26, 2007 at 11:52:50AM +0100, Luciano Rocha wrote:
On Fri, Oct 26, 2007 at 11:28:37AM +0100, Tom Brown wrote:
Hi
I am sure the answer here is really easy but i am stuck!
# mount | grep data | awk '{print$1,$2,$3}'
gives me the info i require locally, however i need to execute this over about 1000 hosts so i run things remotely using ssh something like
# MOUNTER=`ssh $i 'mount | grep data | awk '{print$1,$2,$3}''`
however this fails as at the end of the line there are 2 ticks eg ' together
Can anyone offer me some syntax help please?
Well, you don't need to run the grep and awk on the other side:
MOUNTER=`ssh $i mount | awk '/data/{print $1,$2,$3}'`
But you can live without the call to mount, too: MOUNTER=`ssh $i awk "'/data/{print $1,$2,$3}'" /etc/mtab`
Oops, wrong c&p: MOUNTER=`ssh $i awk "'/data/{print $1,$2,$3}'" /etc/mtab`