1

I decided to make a shell script for basic nmap scanning so I did it like this :

#!/bin/bash

sudo apt-get install nmap 

printf "enter the name of site to do basic scan on >>>"

read NAME

nmap $NAME

echo "Do you wish to do Software Version scan?"
select yn in "Yes" "No"; do
    case $yn in
        Yes ) goto 17; break;;
        No ) exit;;

nmap $NAME -sV

echo "Do you wish to do OS scan?"
select yn in "Yes" "No"; do
    case $yn in
        Yes ) goto 25; break;;
        No ) exit;;

nmap $NAME -O

But the output was :

Nmap done: 1 IP address (1 host up) scanned in 109.97 seconds
Do you wish to do Software Version scan?
./nmap-basic.sh: line 17: syntax error near unexpected token `$NAME'
./nmap-basic.sh: line 17: `nmap $NAME -sV'

Any solutions?

2
  • N.B. checking that nmap is not installed before running the apt-get command would make this script much quicker and easier to use. – Wilf Sep 8 '14 at 21:28
  • I guess i will try to make it work :) – veyo Sep 9 '14 at 9:34
5

case in bash should end in esac, select should end in done. I don't see those keywords in your script.

select NAME [in WORDS ... ;] do COMMANDS; done
case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac
1
  • Thanks, I am starting out with shell scripting, so thanks for advice :) – veyo Sep 9 '14 at 7:52
-1

your shell script has a alot problem, i rewrite that for you.

#!/bin/bash
echo -en "Enter name of website ?"
read name
echo -e "\e[93mScanning...\e[0m"
nmap $name
# software Scan
echo "############################################"
echo "Do you wish to do Software Version scan?"
read ans
    if [ "$ans" = "yes" ] || [ "$ans" = "YES" ]
     then   
    echo "############################################"
    echo -e "\e[91m Software Scanning...\e[0m" 
    nmap -sV $name
    fi
## OS Scan
echo "Do you wish to do OS scan?"
read ans
    if [ "$ans" = "yes" ] || [ "$ans" = "YES" ]
      then
    echo -e "\e[92m OS Scanning...\e[0m" 
    sudo nmap -O $name
     fi 
exit 0

in fact you don't need select command because in "no" case you don't have any work to do , and you can use break|continue in loop not in case statement. i added some color to make it beauty. have fun bro

4
  • 1
    You should make it a habit to use $var inside double quotes. Single quotes are not the same (your nmap -sV '$name' won't work), and no quotes is usually a bad idea (the variable contents may be split and globbed). – Martin Thornton May 24 '16 at 14:37
  • it depends on your input bro , in this situation works fine. for example if my input consist single quote you said right in the worst case name is ip address of target. but thanks anyway – user3607303 May 24 '16 at 15:47
  • 1
    But you have used single quotes. Your line nmap -sV '$name' will give the error Failed to resolve "$name". – Martin Thornton May 24 '16 at 16:08
  • it does n't need any quotes at all. – user3607303 May 25 '16 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.