Running nmap via bash script

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running nmap via bash script
# 1  
Running nmap via bash script

Hello fellow scripters...

I am trying to set up a script for work that reads the contents of a file of IP address and network names, takes these and runs a given nmap scan against them and then saves the output to a file with the filename of the network name.

Such as...

IP file looks like this: network1 network2

Script would cat the contents of this file, take the IP portion and put it in the nmap scan command and then the output of that nmap scan would be saved to a file called network1.nmap, network2.nmap, etc.

Is this possible? If so, how? It seems like I need to do *something* with the IP file so that the network address and name are saved/referenced separately I just can't figure out what I need to do to make this happen.

Thank you for any assistance and guidance you can offer!

------ Post updated at 05:06 PM ------

I am slightly new to scripting and volunteered to see if I could work this out to give myself some experience in both scripting and online research.
# 2  
Everything is "possible".

When you post here, you should post your coding attempt and work, as this is a technical support forum and we prefer people do post their work and what they have tried to do.

What have you tried? What code have you attempted so far?
# 3  
Here's my script:

NETWORKS='šat networks.txt'
     nmap -sn -oN /root/Desktop/$NETWORK
echo "Finished!"

The networks.txt file has my list of network addresses I want to scan. If I enter a single IP address, like, the script works fine and the outpu file is named But when I enter a network address, like, script errors off saying it cannot open file /root/Desktop/ for writing. This error tells me the script is at least SEEING the right information in the txt file it's just not processing it properly. If I put single ' marks around $NETWORK so that it reads /root/Desktop/'$NETWORK' the script runs and the output file name is $NETWORK and not

Is there a way to associate each network address by a number instead of a name and reference that number? Like:


So I would code the script to take the network address and save it in a file name by its associated number (#1.nmap, #2.nmap, etc.)

# 4  
It's always good to search the forums before posting a question (it's also a core forum rule... ).

For example, see:

Nmap shell script goes in infinite loop

... seems to have all the ingredients to help you solve your problem.
# 5  
Thank you! That additional thread helped, along with a little extra tweaking. I've got it working now. I appreciate the assist!
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #235
Difficulty: Easy
The ARPANET was operated by the military during the two decades of its existence, until 1990.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Running options in bash script

Hello UNIX & Linux Forums community! Long time Linux daily user hobbyist, new to shell scripting.... I'm working on a script that does all the "work" in one script, and makes calls to a second script to display info to the user via mostly expanding variables in heredocs. I'm contemplating... (6 Replies)
Discussion started by: Cody Learner
6 Replies

2. UNIX for Dummies Questions & Answers

Feed Input to a script running on bash

Hi Sir, I am just learning bash scripting and I came across a challenge. I need to input F11 to a script among many text inputs. For all the text inputs i did following. # sh < input.txt where input.txt contains all the text inputs in new lines. This worked fine until i... (1 Reply)
Discussion started by: gaurav kumar
1 Replies

3. Shell Programming and Scripting

Bash shell script to check if script itself is running

hi guys we've had nagios spewing false alarm (for the umpteenth time) and finally the customer had enough so they're starting to question nagios. we had the check interval increased from 5 minutes to 2 minutes, but that's just temporary solution. I'm thinking of implementing a script on the... (8 Replies)
Discussion started by: hedkandi
8 Replies

4. Shell Programming and Scripting

script running by sh but not by bash

execute the attached script as, bash -x "/export/home/e120945/INFORMATICA_MAPPING_GENERATOR/SOURCE" "INFA_TEMPLATE.csv" "/export/home/e120945/INFORMATICA_MAPPING_GENERATOR/TARGET" "UNIX" "/export/home/e120945/INFORMATICA_MAPPING_GENERATOR/SETUP"... (5 Replies)
Discussion started by: 120945
5 Replies

5. UNIX for Dummies Questions & Answers

Help Running a Check in Bash Script

Hey guys, so I wrote a small script that pretty much just takes in two numbers and counts from the first to the second, e.g. unknown-hacker|544> 1 3 1 2 3 My problem is I want to make it so that if you input invalid parameters, such as non-numerical characters, more than 2... (2 Replies)
Discussion started by: Duo11
2 Replies

6. UNIX for Dummies Questions & Answers

Running Executable in Bash Script

Hey guys, so I've been trying to write a bash script called that runs an executable that also takes in some parameters and outputs the results to a text file. The executable, sorter, takes in a number parameter. I want to make it so that you can input as many number parameters into... (4 Replies)
Discussion started by: Duo11
4 Replies

7. Shell Programming and Scripting

Validate BASH script before running it...

Hello, Is there some way to validate a bash script before running it. I want to make sure all of the syntax and everything is good so that I dont get a false return code. Thanks, tom (7 Replies)
Discussion started by: tjones1105
7 Replies

8. Shell Programming and Scripting

Script running in bash 3.0 not in 3.2

I have wasted one working day writing this scripts. It compares two folders and make a good tabbed report about their differences. #!/bin/bash function DRAW_DEPTH () { ROUND=$1 while do printf %s " " ROUND=`expr $ROUND - 1` done printf %s "|- " } function MAIN () {... (9 Replies)
Discussion started by: trutoman
9 Replies

9. UNIX for Advanced & Expert Users

debugging an already running bash script

# ps -ef | grep rc root 13903 1 0 08:56 ? 00:00:00 /usr/sbin/automount --timeout=60 /archive file /etc/auto_archive root 10706 1 0 08:55 ? 00:00:00 /bin/bash /etc/rc.d/rc 3 root 2933 20071 0 19:38 pts/1 00:00:00 grep rc Is there any way to debug the... (1 Reply)
Discussion started by: marcpascual
1 Replies

10. Linux

Cannot running export database using bash script

Hi all, I'm new in linux. When I try to run a bash script, it doesn't execute and i receive the following error message 20070321:220002|ERROR||exportDatabase.bash|Another EXPORT process (pid=2799) is still running. If i kill this pid, i receive "No such process". This process was running... (5 Replies)
Discussion started by: tovohery
5 Replies

Featured Tech Videos