Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to escape $0 in awk script within 2 ssh sessions. Works in 1 ssh session
    text
    copied!<p>I am having trouble getting a script to run.</p> <p>The following script works perfectly (awk within an SSH session):</p> <pre><code>ssh root@DB01 "cat /tmp/$togo \ |openssl aes-256-cbc -d -salt -pass pass:aaaaaaaaaaaaa \ |gunzip \ |gawk -v envbucket='design.test.bucket' -v prodbucket='design.bucket' '{gsub(prodbucket,envbucket);print \$0}' \ |gawk -v envbucket='data.test.bucket' -v prodbucket='data.bucket' '{gsub(prodbucket,envbucket);print \$0}' \ | mysql -u root -p'secret' appdb" </code></pre> <p>But when I try to run the exact same thing inside an ssh session within an ssh session, it fails:</p> <pre><code>ssh root@intermediateserver "ssh root@DB02 \"cat /tmp/$togo \ |openssl aes-256-cbc -d -salt -pass pass:aaaaaaaaaaaaa \ |gunzip \ |gawk -v envbucket='design.test.bucket' -v prodbucket='design.bucket' '{gsub(prodbucket,envbucket);print \$0}' \ |gawk -v envbucket='data.test.bucket' -v prodbucket='data.bucket' '{gsub(prodbucket,envbucket);print \$0}' \ | mysql -u root -p'secret' appdb\"" </code></pre> <p>This script works if I remove the 2 gawk commands and pipe the gunzip output directly into mysql. But with the gawk commands in the pipeline, the output becomes empty.</p> <p>I assume it has something to do with the print $0 not escaping properly within the double-quotes within the double-quotes.</p> <p>I've been stuck on this for a while so I'm hoping someone here can help.</p> <p>P.S. I am aware of the security risks associated with these script. In their current form, they are only being run in a test environment.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload