[Solved] Script is ignoring  


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Script is ignoring  
# 1  
Old 01-09-2013
[Solved] Script is ignoring  

Experts,

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

Code:
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:
Code:
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".
Code:
1 ser7b  1 ser7c  2 ser7d  2 ser7e.....

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

Last edited by radoulov; 01-09-2013 at 05:55 AM.. Reason: Marked as solved.
# 2  
Old 01-09-2013
Code:
netstat -a | grep -w 9071 |grep ESTABLISHED | awk '{print $5}' | cut -d'.' -f1

This can be reduced from 5 commands to 2
Code:
netstat -a | awk '/ESTABLISHED/ && /9071/ {split($5,a,"."); print a[1]}'

This User Gave Thanks to Jotne For This Post:
# 3  
Old 01-09-2013
Thanks Jotne and can you help my main problem as well.
# 4  
Old 01-09-2013
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.
# 5  
Old 01-09-2013
Sorry, but my experience with sendmailis limited.
You can try to save output til a variable, and then use it with sendmail.
# 6  
Old 01-09-2013
Quote:
Originally Posted by Corona688
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.

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 Smilie

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

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

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

Thanks for your time Jotne and Corona Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to replace multiple "&nbsp;" entry with in <td> tag into single entry using sed?

I have the input file like this. Input file: 12.txt 1) There are one or more than one <tr> tags in same line. 2) Some tr tags may have one <td> or more tna one <td> tags within it. 3) Few <td> tags having "<td> &nbsp; </td>". Few having more than one "&nbsp;" entry in it. <tr> some td... (4 Replies)
Discussion started by: thomasraj87
4 Replies

2. Shell Programming and Scripting

SFTP Shell Script Get & Delete && Upload & Delete

Hi All, Do you have any sample script, - auto get file from SFTP remote server and delete file in remove server after downloaded. - only download specify filename - auto upload file from local to SFTP remote server and delete local folder file after uploaded - only upload specify filename ... (3 Replies)
Discussion started by: weesiong
3 Replies

3. Shell Programming and Scripting

[Solved] Isolating & Counting IP from log file

Dear Community, today my website was under attack for several hours. 2 specific IPs make a tons of "get requests" to a specific page and apache server goes up and down. Now the problem is solved because I put in firewall blacklist these IPs, but I took a lot of time to analyze the apache log to... (6 Replies)
Discussion started by: Lord Spectre
6 Replies

4. Shell Programming and Scripting

[Solved] Get files & delete them by shell script

I want to use my script to get any file then delete it once it transfers to my side , I manage to create below script to generate "list" file which contains all file names in "10.10.1.1" then I made "a.out" file which contains the commands that I want to run it on "10.10.1.1" to get & delete the... (2 Replies)
Discussion started by: arm
2 Replies

5. Shell Programming and Scripting

[Solved] BASH - chaining TEST and COMMAND with && and II

Can you explain what this line of script is doing. What I have understood is : -- variable C is the name of a software which is either not installed, so it must be installed or allready installed and then should be update if newer version found -- branch B="$B $C" is to install the software --... (4 Replies)
Discussion started by: jcdole
4 Replies

6. UNIX for Dummies Questions & Answers

[solved] Where & what bash env file, Mac OS?

Hi! I wanted to simplify my bash prompt, so I edited my etc/bashrc file. I thought this was the file that would override any other env files. When I opened it, I saw that the way it was setup was not what my prompt looked like, although I forget exactly what was there. But i edited it the way I... (1 Reply)
Discussion started by: sudon't
1 Replies

7. UNIX for Dummies Questions & Answers

[Solved] Using awk to obtain minimum of each column (ignoring zeros)

Hi, I have a wide and long dataset which looks as follows: 0 3 4 2 3 0 2 2 ... 3 2 4 0 2 2 2 3 ... 0 3 4 2 0 4 4 4 ... 3 0 4 2 2 4 2 4 ... .... I would like to obtain the minimum of each column (ignoring zero values) so the output would look like: 3 2 4 2 2 2 2 2 I have the... (3 Replies)
Discussion started by: kasan0
3 Replies

8. Shell Programming and Scripting

Simple Bash Script:ignoring --exclude?

My super simple script works fine when I type it in manually but when I run it from a file as a script the --exclude option is ignored...what am I missing here? #!/usr/bin/bash tar czvf PackUpCases case0* log* --exclude runtpe (5 Replies)
Discussion started by: cpabrego
5 Replies

9. Shell Programming and Scripting

Is it possible - SCP script ignoring certain files

Hey everyone. First, let me preface this post by stating that there are some bad things I'm doing. I'm using python to work around SCP's refusal to take standard input for a password. The reason for doing this as opposed to using keys is because the servers are on lock down due to them being in our... (1 Reply)
Discussion started by: msarro
1 Replies

10. UNIX for Dummies Questions & Answers

&nbsp; ??

What does &nbsp; do ?? I have read this in a question but have never come accross it. (5 Replies)
Discussion started by: finster
5 Replies
Login or Register to Ask a Question