LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bash scripting question (https://www.linuxquestions.org/questions/programming-9/bash-scripting-question-527294/)

Thatch 02-10-2007 08:02 AM

Bash scripting question
 
Hi

i'm writing a bash script to scan a port of an IP and then prompt me to either scan another or exit, (basic i know but i have no scripting or programming knowlegde and i'm learning)

i cant seem to get the script to prompt me to scan again or quit. can anyone tell me where i have gone wrong. below is my script.

#!/bin/bash
hpinger()
{

echo enter IP address
read ip_address

echo enter port
read port

hping $ip_address -c 1 -S -p $port >hpingscan
}

hpinger
grep "flags=SA" /home/bash/bin/hpingscan > /dev/null 2>&1

if [ "$?" -eq 0 ]; then
clear
echo "port open"
exit
else
echo "port closed"

fi

sleep 2
echo "1. another scan"
echo "2. Exit"

echo "Enter your choice: "
read choice


case $choice in
1) hpinger # call hpinger() function
;;
2) exit # exit
esac


Thanks for any help

Thatch:confused:

Dark_Helmet 02-10-2007 08:51 AM

You don't see the menu because of the line in red -- your script quits, completely, if the port is open.
Code:

#!/bin/bash
hpinger()
{
  echo enter IP address
  read ip_address

  echo enter port
  read port

  hping $ip_address -c 1 -S -p $port >hpingscan
}

hpinger
grep "flags=SA" /home/bash/bin/hpingscan > /dev/null 2>&1

if [ "$?" -eq 0 ]; then
  clear
  echo "port open"
  exit
else
  echo "port closed"
fi

sleep 2
echo "1. another scan"
echo "2. Exit"

echo "Enter your choice: "
read choice

case $choice in
  1) hpinger # call hpinger() function
  ;;
  2) exit # exit
esac


Thatch 02-11-2007 02:44 AM

Thanks Dark Helmet, that fixed that one but then brought to light another problem with the script, but i'll work on that one myself.

many thanks

Thatch


All times are GMT -5. The time now is 05:48 PM.