1833780 Members
2289 Online
110063 Solutions
New Discussion

ssh and awk

 
SOLVED
Go to solution
Adam Noble
Super Advisor

ssh and awk

Hi all,

I'm running a little ssh script to obtain memory information using adb and also show crash directory sizing. Its pretty simple but I just don't get the way I have had to script it to get it to work specifically this line.

ssh ${i} "bdf /var/adm/crash | grep -iv File | awk '{print \"total space \"\$2\" Freespace \"\$4}'"

Why do I need the ignore special characters slash???? I don't when I run it locally on my linux server or remotely on the hp box. I just don't get it.
2 REPLIES 2
James R. Ferguson
Acclaimed Contributor
Solution

Re: ssh and awk

Hi Adam:

By outer double quotes cause the contents between to be treated as one argument. The inner, escaped double quotes are required to preserve the quote character at that point. Consider the difference between:

# echo "this is \"it\" ok?"
this is "it" ok?

# echo "this is "it" ok?"
this is it ok?

Regards!

...JRF...
Heironimus
Honored Contributor

Re: ssh and awk

When you run remote commands like that it's also important to be conscious of how many different shells are involved. The command above actually gets interpreted by a shell twice, first on the local machine and again on the remote machine.

Using single quotes wherever possible helps keep things simple. If you put your awk expression in double quotes instead you would need to use \\\" and \\\$ because the remote shell would have to see \" and \$ to pass " and $ through to awk. And just think how messy it would get if you then tried to print a quote in the awk output.