LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-25-2015, 04:11 PM   #1
karthik4455
LQ Newbie
 
Registered: Aug 2014
Posts: 9

Rep: Reputation: Disabled
error while running command in ssh quiet mode


I'm trying to run a pretty lengthy command in my perl script using ssh -q function but it doesn't accept the command as it gives error:
bash: syntax error near unexpected token '('

Command I'm trying to run is:

ssh -q hostname 'stats1.pl stats:dat | grep data | grep -w 0 | awk '{system("cat /opt/jhh/etc/configuration.xml | grep "$1)}' | awk -F"=" '{print $6}' | awk '{print $1}' | sed 's/>//g' | tr -d '"''

I can give a short explanation about why I need such a lengthy command:
I will receive a output here:
stats1.pl stats:dat | grep data | grep -w 0
61574 | hostname_A | data | 1 | N/A | 0
61575 | hostname_A | data | 1 | N/A | 0

Only the items matching data and has 0 will list there.

Then I want 61574 & 61575 to be searched in a configuration file and get the output which is why I use the below:
stats1.pl stats:dat | grep data | grep -w 0 | awk '{system("cat /opt/jhh/etc/configuration.xml | grep "$1)}'
Output I will receive like:
device="61574" name="hostname_A" ip="127.0.0.1" platform="Cisco" protocol="tcp" user="admin"
device="61575" name="hostname_A" ip="10.0.0.1" platform="Cisco" protocol="tcp" user="admin"

Here I want to know the platform hence using the command stats1.pl stats:dat | grep data | grep -w 0 | awk '{system("cat /opt/jhh/etc/configuration.xml | grep "$1)}' | awk -F"=" '{print $6}' | awk '{print $1}' | sed 's/>//g' | tr -d '"'
this will give me below result:

cisco
cisco

Any help here is appreciated as I'm struck without able to execute this via script.

I'm seeing the error below. I'm afraid even if I manage to correct the below error it will prompt more and I need a solution to execute this command via Quiet mode.
[karthik4455@mastghg ~]$ ssh -q hostname 'stats1.pl stats:dat | grep data | grep -w 0 | awk '{system("cat /opt/jhh/etc/configuration.xml | grep "$1)}' | awk -F"=" '{print $6}' | awk '{print $1}' | sed 's/>//g' | tr -d '"''
bash: syntax error near unexpected token '('

Best Regards,
Karthik
 
Old 09-25-2015, 04:17 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quotes don't nest like that. You open a single quote at the start of the command and then close it (it looks like you're attempting to open a second one) in your awk.

You need to re-think the way you're writing your command so you aren't trying to nest quotes of the same type.

Last edited by suicidaleggroll; 09-25-2015 at 04:19 PM.
 
1 members found this post helpful.
Old 09-25-2015, 04:23 PM   #3
karthik4455
LQ Newbie
 
Registered: Aug 2014
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by suicidaleggroll View Post
Quotes don't nest like that. You open a single quote at the start of the command and then close it (it looks like you're attempting to open a second one) in your awk.

You need to re-think the way you're writing your command so you aren't trying to nest quotes of the same type.
I can run this command without any issue within the host:
[karthik4455@mastghg ~]$ stats1.pl stats:dat | grep data | grep -w 0 | awk '{system("cat /opt/jhh/etc/configuration.xml | grep "$1)}'
device="61574" name="hostname_A" ip="127.0.0.1" platform="Cisco" protocol="tcp" user="admin"
device="61575" name="hostname_A" ip="10.0.0.1" platform="Cisco" protocol="tcp" user="admin"

But when I try to run with quite mode outside of the host it's gives error:
[karthik4455@karthik ~]$ ssh -q mastghg 'stats1.pl stats:dat | grep data | grep -w 0 | awk '{system("cat /opt/jhh/etc/configuration.xml | grep "$1)}''
bash: -c: line 0: syntax error near unexpected token '('

If this way doesn't work any other suggestion how can I get the result without using awk '{system("cat /opt/jhh/etc/configuration.xml | grep "$1)}'

Last edited by karthik4455; 09-25-2015 at 04:24 PM.
 
Old 09-25-2015, 04:27 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Again, you can't nest quotes of the same type.

Read through your full ssh command, you have an open single quote after mastghg, this quote is CLOSED after the awk, and then opened and immediately closed again at the end of the command.

When you run
Code:
echo var1'var2'var3'var4'var5
it looks like
Code:
echo var1'var2'var3'var4'var5
when what you apparently want is
Code:
echo var1'var2'var3'var4'var5
with the var3 in its own quote pair inside the outer quote pair. But you can't nest quotes of the same type like that. When you open one, the next one it runs into will close the first, it won't open a second. So this:
Code:
ssh -q mastghg 'stats1.pl stats:dat | grep data | grep -w 0 | awk '{system("cat /opt/jhh/etc/configuration.xml | grep "$1)}''
gets interpreted like this:
Code:
ssh -q mastghg 'stats1.pl stats:dat | grep data | grep -w 0 | awk '{system("cat /opt/jhh/etc/configuration.xml | grep "$1)}''

Last edited by suicidaleggroll; 09-25-2015 at 04:28 PM.
 
1 members found this post helpful.
Old 09-25-2015, 04:38 PM   #5
karthik4455
LQ Newbie
 
Registered: Aug 2014
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by suicidaleggroll View Post
Again, you can't nest quotes of the same type.

Read through your full ssh command, you have an open single quote after mastghg, this quote is CLOSED after the awk, and then opened and immediately closed again at the end of the command.

When you run
Code:
echo var1'var2'var3'var4'var5
it looks like
Code:
echo var1'var2'var3'var4'var5
when what you apparently want is
Code:
echo var1'var2'var3'var4'var5
with the var3 in its own quote pair inside the outer quote pair. But you can't nest quotes of the same type like that. When you open one, the next one it runs into will close the first, it won't open a second. So this:
Code:
ssh -q mastghg 'stats1.pl stats:dat | grep data | grep -w 0 | awk '{system("cat /opt/jhh/etc/configuration.xml | grep "$1)}''
gets interpreted like this:
Code:
ssh -q mastghg 'stats1.pl stats:dat | grep data | grep -w 0 | awk '{system("cat /opt/jhh/etc/configuration.xml | grep "$1)}''
Thank you it makes sense to me. I have now edited the command as below by removing quotes after mastghg

[karthik4455@karthik ~]$ ssh -q mastghg stats1.pl stats:dat | grep data | grep -w 0 | awk '{system("cat /opt/jhh/etc/configuration.xml | grep "$1)}'
cat: /opt/jhh/etc/configuration.xml: No such file or directory
cat: /opt/jhh/etc/configuration.xml: No such file or directory

I guess now the execution is not happening correctly. Output from the first part is not linked correctly with the latter. It goes well in the actual host.
[karthik4455@mastghg ~]$ stats1.pl stats:dat | grep data | grep -w 0 | awk '{system("cat /opt/jhh/etc/configuration.xml | grep "$1)}'
device="61574" name="hostname_A" ip="127.0.0.1" platform="Cisco" protocol="tcp" user="admin"
device="61575" name="hostname_A" ip="10.0.0.1" platform="Cisco" protocol="tcp" user="admin"
 
Old 09-25-2015, 04:46 PM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Your command to ssh has to be in quotes. You'll need to revisit how your quoting is performed inside your command itself. I think you can do without a couple of them, if not you might be able to delimit the inner ones. You need to watch out where that $1 is expanded though.

Last edited by suicidaleggroll; 09-25-2015 at 04:51 PM.
 
Old 09-25-2015, 05:01 PM   #7
karthik4455
LQ Newbie
 
Registered: Aug 2014
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by suicidaleggroll View Post
Your command to ssh has to be in quotes. You'll need to revisit how your quoting is performed inside your command itself. I think you can do without a couple of them, if not you might be able to delimit the inner ones. You need to watch out where that $1 is expanded though.
Can you suggest some other way to get this done like using "exec" or any other. I guess the current command set doesn't allow me to stop using double quotes.
 
Old 09-25-2015, 05:25 PM   #8
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
You could try to delimit the inner quotes, or switch from single to double quoting where necessary, eg:
http://stackoverflow.com/questions/2...e-bash-command
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with ssh quiet mode karthik4455 Linux - General 2 09-25-2015 07:30 PM
[SOLVED] Brightside quiet mode Pastychomper Linux - Desktop 1 10-02-2013 08:20 AM
long mode not supported error while running Solaris 11 in live mode sco1984 Solaris / OpenSolaris 3 11-16-2011 01:48 AM
how to set ssh/putty session running in disconnected mode aamerjavaid Linux - Newbie 7 07-08-2011 08:53 AM
ssh's command mode bits Linux - Newbie 3 08-13-2009 06:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration