title: Shell Script ssh $SERVER >> EOF
body: <p>I have a handy script here that can return accounts that will expire in 7 Days or have expired. I wanted to allow this to run on multiple hosts with out putting the script on each individual host, I added the <code>for loop</code> and the <code>ssh $SERVER &gt;&gt; EOF</code> part but it will just run the commands off they system that is running the script.</p>
  
  <p>I believe the error is with <code>ssh $SERVER &gt;&gt; EOF</code> but I am unsure as the syntax looks correct. </p>
  
  <pre><code>#!/bin/bash
  
  for SERVER in `cat /lists/testlist`
  do
    echo $SERVER
  
    ssh $SERVER &gt;&gt; EOF
      sudo cat /etc/shadow | cut -d: -f1,8 | sed /:$/d &gt; /tmp/expirelist.txt
      totalaccounts=`sudo cat /tmp/expirelist.txt | wc -l`
      for((i=1; i&lt;=$totalaccounts; i++ ))
      do
        tuserval=`sudo head -n $i /tmp/expirelist.txt | tail -n 1`
        username=`sudo echo $tuserval | cut -f1 -d:`
        userexp=`sudo echo $tuserval | cut -f2 -d:`
        userexpireinseconds=$(( $userexp * 86400 ))
        todaystime=`date +"%s"`
        if [[ $userexpireinseconds -ge $todaystime ]] ;
        then
          timeto7days=$(( $todaystime + 604800 ))
          if [[ $userexpireinseconds -le $timeto7days ]];
          then
            echo $username "is going to expire in 7 Days"
          fi
        else
          echo $username "account has expired"
        fi
      done
      sudo rm /tmp/expirelist.txt
    EOF
  done
  </code></pre>