LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-10-2007, 08:02 AM   #1
Thatch
LQ Newbie
 
Registered: Feb 2007
Location: UK
Distribution: Kubuntu + Backtrack
Posts: 2

Rep: Reputation: 0
Question 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
 
Old 02-10-2007, 08:51 AM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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
 
Old 02-11-2007, 02:44 AM   #3
Thatch
LQ Newbie
 
Registered: Feb 2007
Location: UK
Distribution: Kubuntu + Backtrack
Posts: 2

Original Poster
Rep: Reputation: 0
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash scripting question bmfan Linux - Software 6 11-04-2005 08:54 PM
A Bash Scripting Question steve_f60 Linux - Newbie 4 05-26-2005 06:57 PM
bash scripting question Andy@DP Programming 4 04-13-2004 05:06 PM
bash scripting question mehesque Programming 2 03-07-2004 01:37 PM
Bash Scripting Question Rezon Programming 2 10-30-2003 10:16 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration