Note that there are some explanatory texts on larger screens.

plurals
  1. POLinux Command within Command
    primarykey
    data
    text
    <p>My use case is to run a command on multiple servers remotely. I have trust set up between hosts.</p> <p>So i have one command like this: COMMAND 1:</p> <pre><code>for i in 11 12 13 14 15 16; do echo host-name-dev-$i; ssh -q host-name-dev-$i "nohup bash -c 'Place Ur command Here' &gt; foo.out 2&gt; foo.err &lt; /dev/null &amp;"; done </code></pre> <p>And another as: COMMAND 2:</p> <pre><code>rm -rf /floderPath </code></pre> <p>When i combine(COMMAND 1 + COMMAND 2) these two it works fine and subsequent folder is deleted from all hosts.</p> <pre><code>for i in 11 12 13 14 15 16; do echo host-name-dev-$i; ssh -q host-name-dev-$i "nohup bash -c 'rm -rf /floderPath' &gt; foo.out 2&gt; foo.err &lt; /dev/null &amp;";done </code></pre> <p>Now i have another command. If i run this command on all the hosts individually, it works fine and kill all the java processes. COMMAND 3:</p> <pre><code>for i in `ps -ef | grep -v grep | grep java | awk '{print $2}'`; do kill -9 $i; echo "Process id $i is killed"; done </code></pre> <p>But now when i combine COMMAND 1 and COMMAND 3 it doesn't work at all. What i am trying to do here is KILLING all JAVA process on all the hosts.</p> <pre><code>for i in 11 12 13 14 15 16; do echo host-name-dev-$i; ssh -q host-name-dev-$i "nohup bash -c 'for j in `ps -ef | grep -v grep | grep java | awk '{print $2}'`; do kill -9 $j; echo "Process id $j is killed"; done' &gt; foo.out 2&gt; foo.err &lt; /dev/null &amp;";done </code></pre> <p>I can guess that there might be improper use of quotes, but i have tried various combinations and it didn't work for me. I don't have much experience in scripting so pardon for obvious errors.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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