Find the answer to your Linux question:
Results 1 to 2 of 2
Code: [root@pxe tmp]# vi test1 #!/bin/bash a="nmap -p80 xx.xx.xx.xx | awk '{print $2}'|grep open" b="open" echo if [ "$a" != "$b" ] then echo "doesn't match" elif ["$a" == "$b" ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2009
    Posts
    24

    BASH and NMAP


    Code:
    [root@pxe tmp]# vi test1
    #!/bin/bash
    
    a="nmap -p80 xx.xx.xx.xx | awk '{print $2}'|grep open"
    b="open"
    
    echo
    
    if [ "$a" != "$b" ]
    then
    echo "doesn't match"
    elif
    ["$a" == "$b" ]
    then
    echo "Matches!"
    fi
    It always comes back as "doesn't match". I also get this error when I have the variable set in the environment:

    Code:
    [root@pxe tmp]# a="nmap -p80 xx.xx.xx.xx| awk '{print $2}'|grep open"
    [root@pxe tmp]# $a
    
    Starting Nmap 4.11 ( http://www.insecure.org/nmap/ ) at 2011-07-11 10:11 MST
    Invalid target host specification: |
    QUITTING!
    I'm thinking this error would be the issue. What am I doing wrong?

    Please note, the xx.xx.xx.xx is actually an IP address in my script

  2. #2
    Just Joined!
    Join Date
    Jul 2009
    Posts
    24
    Fixed, here's the revised script:


    Code:
    #!/bin/bash
    
    a=$(nmap -p80 xx.xx.xx.xx | awk '{print $2}'|grep open)
    b="open"
    
    eval "$a"
    echo
    
    if [ "$a" != "$b" ]
    then
    service httpd start
    fi

Posting Permissions

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