I'm trying to filter data from a file and send an email when specific info\error codes are found. The first line of the script is for manipulation, and the second part I got from https://unix.stackexchange.com/a/246872/181400 to complete the email sending part.

I need to know about all errors that have 400 id and north, I am trying to realize why I am not getting the full extant of the file- Could it be that it is because the second END statement?

    { awk 'BEGIN{print "Subject:App Error \nFrom:Server \nTo:email@address.com"}
   END{printf("%s\015\n", $1" | "$2" | "$3" | "$4)}  END{if($1<399){exit(1)}}' \
   /tmp/err.txt || exit; } > (/usr/lib/sendmail -t email@address.com)

This is the data I get in the file:

     label  responseCode
     info data  404
     Get info data  404
     get user info data  403
     create landmark  403
     ........ More lines of the same come after this....

And this is what I get through the mail:

      create | landmark | 403 |  

Does anybody have any idea on this matter ? Thanks!

  • The data file you show doesn't make sense since the first awk command specifies a , as the field delimiter. Which means the $3 and $4 in the command will be blank for every line. And the last part of the script, the > > part is invalid. Can you check your script and data file and update your post? – Unbeliever Oct 13 '16 at 21:21
  • The file received is after the manipulation, so it is indeed correct. but I will remove it so it wont be confusing any longer. Regarding the > > It did seem weird to me as well - I will sort it out - thanks for the tips. – Busted Oct 13 '16 at 22:01
  • My misunderstanding then, could you post the source data as well? – Unbeliever Oct 13 '16 at 22:51
  • I eventually simplified the script to send the filtered file any way. thanks for try to help! – Busted Oct 16 '16 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.