LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 05-04-2004, 11:40 PM   #1
AMMullan
Member
 
Registered: Sep 2003
Location: United Kingdom
Distribution: Ubuntu, Arch
Posts: 438

Rep: Reputation: 30
Subsystem shell


Hey all

I'm trying to get port numbers to sit in an array in a bash script but not sure how to use subsystem shells properly. Can anyone tell me what i've done wrong in the following:

Code:
#! /bin/bash

FILE=/tmp/a.tmp

echo -n "Enter a server: "
read SERVER

nmap ${SERVER} > ${FILE}
CNT=0

cat ${FILE} | grep ^[0-9] | cut -d'/' -f 1 | cut -d' ' -f 1 | while read LINE
do
  PORT[${CNT}]=$LINE
  (( CNT += 1 ))
done

TMP=0
while [ $TMP -lt $CNT ]
do
  echo "Port-${TMP} : $PORT[${TMP}]"
  (( TMP += 1 ))
done
Thanks in advance
 
Old 05-05-2004, 03:53 PM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
I can't tell what the cut statements are doing, but I changed the increment
for the loop counters.

Code:
FILE=/tmp/a.tmp

echo -n "Enter a server: "
read SERVER

nmap ${SERVER} > ${FILE}
CNT=0

cat ${FILE} | grep ^[0-9] | cut -d'/' -f 1 | cut -d' ' -f 1 | while read LINE
do
  echo $LINE                   # try this to see if you are getting data
  PORT[${CNT}]=$LINE
  let CNT=CNT+1
done

TMP=0
while [ $TMP -lt $CNT ]
do
  echo "Port-${TMP} : $PORT[${TMP}]"
  let TMP=TMP+1
done
 
Old 05-05-2004, 04:09 PM   #3
AMMullan
Member
 
Registered: Sep 2003
Location: United Kingdom
Distribution: Ubuntu, Arch
Posts: 438

Original Poster
Rep: Reputation: 30
I tried this but it still doesn't work properly - the count should go up and as it does it should add a port to the array....

I.e.

PORT[0] = 22
PORT[1] = 25

Not sure whats going on, this should just ork but thats why I think it's got something to do with the subshell...
 
Old 05-05-2004, 04:47 PM   #4
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
What output do you get from the changes I posted?

What is the input line from the file?
 
Old 05-05-2004, 05:23 PM   #5
AMMullan
Member
 
Registered: Sep 2003
Location: United Kingdom
Distribution: Ubuntu, Arch
Posts: 438

Original Poster
Rep: Reputation: 30
From what you posted I get a list of ports but it only lists once and if I add a
Code:
echo ${CNT}
after the array setup it still says 0...

The input line from the file is the cat statement that cuts the line with the ports out and then cuts the port from line.
 
  


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
Replace Disk Subsystem and new motherboard btrthnwin Linux - Software 3 09-26-2005 11:25 PM
Wolfenstein can't load OpenGL subsystem pAn1k Linux - Games 4 09-18-2005 02:16 PM
X subsystem? gdays DamnSmallLinux 6 06-30-2005 06:02 PM
gcc configuration subsystem frelihm Linux - Software 7 09-06-2004 03:54 AM
openGL subsystem... pAn1k Linux - Games 3 07-10-2004 10:55 PM

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

All times are GMT -5. The time now is 08:53 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration