title: using pgrep substitution with ssh
body: <p>I have a mongod instance running on &quot;HOST&quot; and &quot;PORT&quot;, and I'm trying to get the ulimit parameters of the process over ssh.</p>
  <p>So the following two command works fine.</p>
  <pre><code>// outputs pid of mongod
  ssh HOST@PORT pgrep mongod
  17215
  
  // outputs ulimit parameters of the process
  ssh HOST@PORT cat proc/17215/limits
  Limit            Soft Limit      Hard Limit     Units
  Max cpu time     ...
  </code></pre>
  <p>So I thought putting $(pgrep mongod) instead of the hard coded value would work too, but it doesn't.</p>
  <pre><code>ssh HOST@PORT cat proc/$(pgrep mongod)/limits
  &gt; cat proc/26394/limits: No such file or directory
  </code></pre>
  <p>Actually there is another mongod running on localhost port 26394. It seems like $(pgrep mongod) outputs local mongod's pid, instead of the remote one. How can I change the last command to get the desired output?</p>
  <p>As a side note, I would like to do it one command line (not like, ssh HOST@PORT; and then cat proc/$(pgrep mongod)/limits).</p>