[Solved] Script is ignoring  

Experts,

I am finding the split up of the Servers which uses the netstat on a specific port.

netstat -a | grep -w 9071 |grep ESTABLISHED | awk '{print $5}' | cut -d'.' -f1 | sort -n | uniq -c
   1 ser7b
   1 ser7c
   2 ser7d
   2 ser7e
   1 ser7f
   1 ser7h
   1 ser7i
   1 ser8b

I am trying to email this details:

print "<br><br>Split up on Port 9071:<br>$(netstat -a| grep -w 9070 |grep ESTABLISHED | awk '{print $5}' | cut -d'.' -f1 | sort -n | uniq -c" > file
cat file | sendmail -t

But when I open my email I can see all the servers split up are aligned in a single line rather than in "\n".

1 ser7b  1 ser7c  2 ser7d  2 ser7e.....

By googling found out that we need to add � to it, can you people help me with it. Thanks

netstat -a | grep -w 9071 |grep ESTABLISHED | awk '{print $5}' | cut -d'.' -f1 

This can be reduced from 5 commands to 2

netstat -a | awk '/ESTABLISHED/ && /9071/ {split($5,a,"."); print a[1]}'
1 Like

Thanks Jotne and can you help my main problem as well.

What are you opening the email in? You may have more luck sending it as a .txt file attachment than expecting a Microsoft email client to arrange text contents unmolested.

Sorry, but my experience with sendmail is limited.
You can try to save output til a variable, and then use it with sendmail .

Corona688, thanks for your reposnse. I am not good at attaching txts with sendmail , also I am not looking for attachments, since the fellas using this alert will ignore if it comes in attachments :frowning:

---------- Post updated at 04:45 AM ---------- Previous update was at 03:35 AM ----------

Found the solution :slight_smile:
By adding <br> at the end , i reached my desired output.

netstat -a | awk '/ESTABLISHED/ && /9071/ {split($5,a,"."); print a[1]}' | sed 's/$/<br>/'

Thanks for your time Jotne and Corona :slight_smile: