title: run shell script on multiple remote machines
body: <p>WARNING: newbie with bash shell scripting.</p>
  
  <p>I've created the script to connect to multiple remote machines, one by one, check if a certain file has certain text already in it, if it does, move to the next machine and make the same check, if not, append the text to the file, then move to the next machine.</p>
  
  <p>Currently, the script connects to the first remote machine but then does nothing when it connects. If I type exit to close the remote machine's connection, it then continues running the script, which does me no good because I'm not connected to the remote machine any longer.</p>
  
  <p>on a sidenote, I'm not even sure if the rest of the code is correct, so please let me know if there are any glaring mistakes. This is actually my first attempt at writing a shell script from scratch.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>#!/bin/bash
  
  REMOTE_IDS=(    root@CENSOREDIPADDRESS1
                  root@CENSOREDIPADDRESS2
                  root@CENSOREDIPADDRESS3
                  )
  
  for REMOTE in "{$REMOTE_IDS[@]}"
  do
  
  ssh -oStrictHostKeyChecking=no $REMOTE_IDS
  
  if grep LogDNAFormat "/etc/syslog-ng/syslog-ng.conf"
      then
          echo $REMOTE
          echo "syslog-ng already modified. Skipping."
          exit
          echo -
      else
          echo $REMOTE
          echo "Modifiying..."
          echo "\n" &gt;&gt; syslog-ng.conf
          echo "### START syslog-ng LogDNA Logging Directives ###" &gt;&gt; syslog-ng.conf
          echo "template LogDNAFormat { template(\"&lt;key:CENSOREDKEY&gt; &lt;${PRI}&gt;1 ${ISODATE} ${HOST} ${PROGRAM} ${PID} ${MSGID} - $MSG\n\");" &gt;&gt; syslog-ng.conf
          echo "template_escape(no);" &gt;&gt; syslog-ng.conf
          echo "};" &gt;&gt; syslog-ng.conf
          echo "destination d_logdna {" &gt;&gt; syslog-ng.conf
          echo "udp(\"syslog-a.logdna.com\" port(CENSOREDPORT)" &gt;&gt; syslog-ng.conf
          echo "template(LogDNAFormat));" &gt;&gt; syslog-ng.conf
          echo "};" &gt;&gt; syslog-ng.conf
          echo "log {" &gt;&gt; syslog-ng.conf
          echo "source(s_src);" &gt;&gt; syslog-ng.conf
          echo "destination(d_logdna);" &gt;&gt; syslog-ng.conf
          echo "};" &gt;&gt; syslog-ng.conf
          echo "### END syslog-ng LogDNA logging directives ###" &gt;&gt; syslog-ng.conf
  
          killall -s 9 syslog-ng
          sleep 5
          /etc/init.d/syslog start
  
          echo -
  fi
  
  
  done</code></pre>
  </div>
  </div>
  </p>