Agnus Dei (jackal) wrote,
Agnus Dei
jackal

bash code to tail a file and return the lines, but if you hit a given line, execute a function

My code blocks the tomcat port when we start up tomcat because I don't want tomcat answering web request until it's 100% up.

At the end of the rc script it tail catalina.out for you and returns the lines to your screen.

I have it wait for the "Server startup" line and when it sees the server startup line it calls the function to remove all the 
iptables block lines I've created.

removing_all_iptables_blocks() {
   # List all the current iptables rules
   #  grep just the INPUT/OUTPUT chain DROP's
   #  ignore any ipsets ('match-set')
   #  loop through them and remove them
    iptables-save |egrep -o 'INPUT.*DROP|OUTPUT.*DROP' |grep -v match-set | while read a
         do
            /sbin/iptables -D $a
         done
}

...


      tail -f /usr/local/tomcat/default/logs/catalina.out | while read LOGLINE
            do
               echo "${LOGLINE}"
               [[ "${LOGLINE}" == *"Server startup in"* ]] && removing_all_iptables_blocks
            done
      echo "Tomcat is started"
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

  • 0 comments