Find the answer to your Linux question:
Results 1 to 4 of 4
Hi there, I need counter in a single file for all connections to port 1352. How I can make an acumulative counter? netstat -n |grep 1352 -c >users_notes.txt this sentence ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2008
    Posts
    7

    Acumulative counter with grep


    Hi there,

    I need counter in a single file for all connections to port 1352. How I can make an acumulative counter?

    netstat -n |grep 1352 -c >users_notes.txt this sentence only save one value, and when I execute again the value is overwritte with the new value

    Thanks a lot

  2. #2
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    hi,


    if you just want to write the value to the new file without deleting the existing values
    you use append as follows
    Code:
    netstat -n |grep 1352 -c >>users_notes.txt
    now if you wanna add the new value to the value existiing in the file then you need a script a little bit more involved(if that is the case we can provide a small script for that).

    but im afraid your command does not count exactly the number of connections. maybe the next one would be a bit more precise.
    Code:
    netstat -n |grep 1352 | grep -i connected -c >>users_notes.txt
    Linux and me it's a love story

  3. #3
    Just Joined!
    Join Date
    May 2008
    Posts
    7
    Thanks a lot Khafa

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    you very welcome
    Linux and me it's a love story

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •