LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 09-24-2003, 05:48 PM   #1
AMMullan
Member
 
Registered: Sep 2003
Location: United Kingdom
Distribution: Ubuntu, Arch
Posts: 438

Rep: Reputation: 30
Problem wth bash script


I created the following script and what it basically does is ask for a server to query and then ping s it, it then echoes the average return time and then uses nmap to tell what ports are open on that host.

The only problem is it works on my home computer but not my work one

SCRIPT:

#! /bin/bash

# The temporary files used by the script
tmp=/tmp/nmapped.$$
ping_temp=/tmp/ping.$$
sharefile=/tmp/sharefile.$$

DOIT=Y

while [ $DOIT = "Y" ]
do {
# Asks you what you want to ping and then puts it out as the variable
if [ $LOGNAME != "root" ] ; then
echo ""
tput bold
echo "WARNING! You must be logged in as 'root' for this script to run properly!"
tput sgr0
else
echo ""
fi
echo ""
echo "-----------------------"
tput bold
echo "(NOTE: THE PID FOR THIS APPLICATION IS $$)"
tput sgr0
echo ""
tput bold
echo -n "What server do you want to test? "
tput sgr0
read server
echo ""
echo "-----------------------"
echo "Pinging $server....."
echo ""

# Pings the server that was entered as the server variable
ping -c 4 $server 2>&1 | grep avg | awk '{print $4}' | cut -d'/' -f2 > $ping_temp
# Checks the server status and then advises of it's status
if [ -s $ping_temp ] ; then
echo "$server responds to ping"
else
echo "$server doesn't appear to be up" ; exit
fi
echo ""
echo "Average reply time - `cat $ping_temp`ms"
echo ""
echo "-----------------------"
echo ""

# Checks server and gets port info
tput bold
echo -n "Do you want detailed information for this server? (y/n) "
tput sgr0
read detail

if [ $detail == "n" -o $detail == "N" ] ; then
exec nmap $server | grep open > $tmp
else
exec nmap -A -T4 -F $server | grep open > $tmp
fi
count=`wc -l $tmp | awk '{print $1}'`
echo "There are $count ports open on \"$server\""
echo ""
echo "-----------------------"
echo ""

# Prints lists of open ports on server
cat $tmp
rm $tmp
rm $ping_temp
echo ""
echo "-----------------------"
echo ""
}
DOIT=N
tput bold
echo -n "Do you want to ping another host? "
tput sgr0
read DOIT
DOIT=`echo $DOIT | tr '[a-z]' '[A-Z]'`
done
 
Old 09-24-2003, 07:34 PM   #2
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 47
What kind of error do you get when you run it at work?
 
Old 09-24-2003, 09:35 PM   #3
AMMullan
Member
 
Registered: Sep 2003
Location: United Kingdom
Distribution: Ubuntu, Arch
Posts: 438

Original Poster
Rep: Reputation: 30
I ftp'd it from my home computer to work and it worked fine, not sure what happened...

Sorry bout that
 
  


Reply



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
Problem with bash script. cheater1034 Programming 9 11-21-2005 10:29 PM
bash script problem fatbastard spice Linux - General 2 08-24-2005 02:15 AM
bash script problem cookie_ie Programming 3 03-23-2005 02:19 PM
bash script problem sorry99 Programming 2 09-20-2004 09:02 AM
Bash script problem kalleanka Programming 2 01-30-2004 11:59 AM

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

All times are GMT -5. The time now is 12:59 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