title: Code to count number of types of files on client in Unix
body: <p>Hi I am new to shell scripting.
  my requirement is:
  There is one server &amp; 3 clients. On each client error logs files are generated which are of 4 types.Say type 1 error , type 2 error like this type 4 error.
  I want to write a script which read all the 3 clients from server  &amp; provide me number of times 4 different type of error logs are genereted on each client. 
  In short it should use ssh &amp; grep command combination.
  I have written the demo script but it's not providing me the number of times different type of logs occured on clients.</p>
  
  <pre><code>#error[1]='Exception: An application error occurred during an address lookup request, please contact IT'
  #error[2]='SocketTimeoutException: Read timed out'
  #error[3]='Exception: The search has produced too many matches to be returned'
  #error[4]='Exception: No matching address found'
  error_1='exception 1'
  error_2='exception 2'
  function get_list_of_clients()
  {
  NUM_OF_CLIENTS=$(wc -l ${CLIENT_IP_LIST} | awk -F " " '{ print $1 }' )
  echo $NUM_OF_CLIENTS
        if [ "${NUM_OF_CLIENTS}" -gt 0 ]
        then
              for ((row=2; row&lt;=$NUM_OF_CLIENTS; row++))
              do
                    CLIENTS_IP=$(sed -n ${row}p ${CLIENT_IP_LIST}| awk -F " " '{print $3 }')
                    echo ${CLIENTS_IP}
   #                 get_number_of_errors
   #                 copy_count_errors
              echo ${$error_$row}
              done
        fi
  
  }
  
  function get_number_of_errors()
  {
  for((row_no=1; row_no&lt;=4; row_no++))
  do
  {
  /usr/bin/expect - &lt;&lt;- EndMark
  spawn ssh root@${CLIENTS_IP} "grep $error[$row_no] var/error.log |wc -l" &gt;&gt; /tmp/${CLIENTS_IP}_error${row_no}.txt
  match_max 50000
    expect {
    "*yes/no*" {
     send -- "yes\r"
     send -- "\r"
     exp_continue
  }
    "*?assword:*" {
     send -- "${CLIENT_PASSWORD}\r"
     send -- "\r"
       }
  
  }
  expect eof
  EndMark
  }
  done
  }
  
  
  function copy_count_errors()
  {
  /usr/bin/expect - &lt;&lt;- EndMark
  spawn scp root@${CLIENTS_IP}:/tmp/${CLIENTS_IP}* /tmp/
  match_max 50000
    expect {
    "*yes/no*" {
     send -- "yes\r"
     send -- "\r"
     exp_continue
  }
    "*?assword:*" {
     send -- "${CLIENT_PASSWORD}\r"
     send -- "\r"
    }
  }
  expect eof
  EndMark
  }
  
  get_list_of_clients
  </code></pre>
  
  <p>================================================================================
  please help.</p>