LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-08-2004, 11:34 AM   #16
AMMullan
Member
 
Registered: Sep 2003
Location: United Kingdom
Distribution: Ubuntu, Arch
Posts: 438

Rep: Reputation: 30

Code:
#! /bin/bash
 
# The temporary files used by the script
 
tmp=/tmp/nmapped.$$
ping_temp=/tmp/ping.$$
sharefile=/tmp/sharefile.$$
   
signal_func() {
  echo
  tput setf 4
  echo -n "Are you sure you want to quit :: "
  tput sgr0
  read QUIT_NOW
  QUIT_NOW=`echo "${QUIT_NOW}" | tr 'a-z' 'A-Z'`
  trap - INT
    if [ "${QUIT_NOW}" == "Y" ] || [ "${QUIT_NOW}" == "YES" ] ; then
      exit 0
    else
      continue
    fi
}
trap 'signal_func' INT
 
DOIT=Y
 
while [ $DOIT = "Y" -o $DOIT = "y" ]
do {
 
date
 
# Asks you what you want to ping and then puts it out as the variable
if [ $USER != "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 setf 2
echo "(NOTE: THE PID FOR THIS APPLICATION IS $$)"
     tput sgr0
echo ""
     tput bold
echo -n "What server do you want to test? (Or type \"quit\" to exit) :: "
     tput sgr0
read server
 
while [ "$server" = "quit" ] || [ "$server" = "" ]
do
 
if [ "$server" == quit ] ; then
  clear
  exit 0
fi
 
if [ "$server" == "" ] ; then
  echo "Gees, are you not going to enter anything?"
  echo
  echo "Exiting..."
  exit 1
fi
done
 
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
  grep avg <(ping -c 4 $server 2>&1) | 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 1
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
  nmap $server 2>&1 | grep open > $tmp
else
  nmap -A -T4 -F $server 2>&1 | 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? (y/n) :: "
    tput sgr0
read DOIT
DOIT=`echo $DOIT | tr '[a-z]' '[A-Z]'`
done
 
Old 02-08-2004, 04:12 PM   #17
Software
LQ Newbie
 
Registered: Jan 2004
Posts: 25

Original Poster
Rep: Reputation: 15
hi all , what's up ..

thank for explaining the grep , tr , and the stream editor ..

-----------
what's the (server "monitor") ?

Last edited by Software; 02-08-2004 at 04:19 PM.
 
Old 02-08-2004, 04:27 PM   #18
Software
LQ Newbie
 
Registered: Jan 2004
Posts: 25

Original Poster
Rep: Reputation: 15
and there is a thing tp disable the functionality of the special characters like the * or /
you can put : set -f beofre you want to handle them , and then when you want them back as special chars you can set it back to +f : set +f

like this :

#!/bin/sh

bla bla ..

set -f

bla ..

set +f
 
Old 02-08-2004, 04:47 PM   #19
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Cool, how do you put that in the script?
 
Old 02-08-2004, 09:38 PM   #20
Software
LQ Newbie
 
Registered: Jan 2004
Posts: 25

Original Poster
Rep: Reputation: 15
just the way i put it

when you write the script , if you wanna disable the * for example and then you want the grep to get it from a file , you do this

somewhere in the script where you want to grep the star :

set -f

# this will disable the special meaning of star , and i guess plenty of other special chars , but i don't know them

grep "*" file.txt

# here it will search for the char * just as it is , it will not expand it to any thing ..

then if you want to work with the star as a special char again ( give it the propety of expanding to take all the files ) you can set it as special char aagin by doing the reversed code which is :

set +f

and you continue writing your code
 
Old 02-08-2004, 10:05 PM   #21
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Well the problem is there are lots of other special characters in that line which still need to be there. I think it's just as easy to "escape" them with the back slash ( \ ). But that's just MHO.

Have you tried it using your method? I played with it some but it didn't work.
 
Old 02-11-2004, 01:28 AM   #22
Software
LQ Newbie
 
Registered: Jan 2004
Posts: 25

Original Poster
Rep: Reputation: 15
ya i know ,
actually in this small code i worked , specially that we were not asked to go deep into the complications of what's inside the comments ( some cases could be terrible like commemts inside comments and and stars ..etc )

i don't have the code at home , i have it on the school's computer , i'll post it when i work there . the prof. said that he is gonna give us a code that deals with all the complications in this program , i'll add it too when we get it .

cheers ..
 
  


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
Problems compiling a simple shell program yekrahs Programming 3 09-26-2005 12:07 PM
simple shell script sharpie Programming 9 06-02-2004 11:47 PM
simple shell script Greg_courageous Programming 2 05-12-2004 04:34 PM
Simple Bash Shell Program frankblack Programming 2 02-14-2003 11:59 PM
Simple C Shell script is not so simple elconde Programming 2 09-16-2001 11:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:26 PM.

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