Thread: Awk and sed bash script help

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    With grep you're using -i (case insensitive) when you want -v (invert match).
    Code:
    PORTS=$(netstat -ant | awk -F" " '{print $5}' | awk -F":" '{print $2}' | sed '/^$/d' | grep -Ev "80|443")
    if [ "$PORTS" ] ; then echo yep ; else echo nope ; fi
    Or a little simpler
    Code:
    if [ "$(netstat -ant | awk '{print $5}' | grep -Eo ":[0-9]+" | grep -Ev ":80|:443")" ] ;
    then echo yep ;
    else echo nope ;
    fi
    Actually, that's not really any simpler.
    Last edited by oogabooga; 05-07-2012 at 10:58 PM.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  2. #2
    Registered User Annonymous's Avatar
    Join Date
    Apr 2011
    Location
    Jackson, New Jersey, United States
    Posts
    302
    Quote Originally Posted by oogabooga View Post
    With grep you're using -i (case insensitive) when you want -v (invert match).
    Code:
    PORTS=$(netstat -ant | awk -F" " '{print $5}' | awk -F":" '{print $2}' | sed '/^$/d' | grep -Ev "80|443")
    if [ "$PORTS" ] ; then echo yep ; else echo nope ; fi

    WOW, so much cleaner than the slop i put together. thanks.

    See the problem i am still having is that ports will always evaluate as true. As long as the net is open. Even if i have a torrent site up with high ports open, it will still be true.

    I am trying to launch the UI if an open port other than 443 or 80 is open.

    I figured, remove all duplicate ports. Remove the asterisk and blank lines. Then count the lines and if there are more than 2, then launch the UI.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help converting bash shell script to windows
    By chelp123 in forum Tech Board
    Replies: 2
    Last Post: 11-24-2011, 02:22 PM
  2. ssh/bash script question
    By Overworked_PhD in forum Tech Board
    Replies: 2
    Last Post: 03-30-2009, 07:48 PM
  3. Bash Script Q
    By QuestionC in forum Tech Board
    Replies: 1
    Last Post: 04-19-2007, 10:16 AM
  4. Linux: Use C to call a bash script
    By harada in forum Linux Programming
    Replies: 9
    Last Post: 10-27-2006, 01:59 PM

Tags for this Thread