LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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

Closed Thread
 
Search this Thread
Old 12-05-2007, 12:26 PM   #1
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,113

Rep: Reputation: 57
Globbing using Korn Shell


I have this script:

PHP Code:
#!/bin/ksh
SNIFFILE="sniffer_output"
OUT="Report"
MAIL_LIST="test_admin@ccc.edu"

$SNIFFILE
$OUT

echo       Daily Sniffer and NAMs Scan as of `date` >> $OUT
echo       Script run with a 5 sec timeout >> $OUT


echo >>$OUT
exec 2
>/dev/null

printf 
" %-8.20s %-15.20s %-8s %-6s \n" SNIFFERS IP_Address Status Telnet >> $SNIFFILE

echo "======================================================" >> $SNIFFILE

for SNIFFERS in $(<snifflist)

do
        
Status=down
        Telnet
=closed
        
if ping $SNIFFERS 5 >/dev/null 2>&1
        then
                Status
=up
                read foo 
< /dev/tcp/$SNIFFERS/23 2>/dev/null &&  Telnet=open
                IP_Addr
="$(nslookup $SNIFFERS | tail -2 |head -1 | awk -F: '{print $2}'| sed 's/ //g'|  cut -d '.' -f1-3 )"
                
IP_Address="${IP_Addr%.*}"
                
[[ -"$IP_Address" ]] && IP_Address="n/a"
                
printf " %-15.20s %-15.20s %-8s %-6s \n" $SNIFFERS $IP_Address $Status $Telnet >>$SNIFFILE
        
else
                
IP_Address="$(nslookup $SNIFFERS | tail -2 |head -1 | awk -F: '{print $2}'| sed 's/ //g')"
                
[[ -"$IP_Address" || "$IP_Address" == "SERVFAIL" ]] && IP_Address="n/a"
                
Telnet="n/a"
                
printf " %-15.20s %-15.20s %-8s %-6s \n" $SNIFFERS $IP_Address $Status $Telnet >>$SNIFFILE

        fi

done


cat $SNIFFILE 
>> $OUT 
This section:

PHP Code:
IP_Addr="$(nslookup $SNIFFERS | tail -2 |head -1 | awk -F: '{print $2}'| sed 's/ //g'|  cut -d '.' -f1-3 )"
                
IP_Address="${IP_Addr%.*}"
                
[[ -"$IP_Address" ]] && IP_Address="n/a" 
Produce this output

PHP Code:
nslookup S00CBBF.aa.bb.ccc.edu tail -3|head -1awk -F'{print $2}'sed 's/ //g'
        
S00CBBF.aa.bb.ccc.edu 
I need this output:

PHP Code:
S00CBBF.aa.bb.ccc.edu 
to produce this output

PHP Code:
S00CBBF.aa.bb 
This is what I believe they call globbing:

PHP Code:
IP_Address="${IP_Addr%.*}" 
so how can I get this to only truncate the last two sections of:

PHP Code:
S00CBBF.aa.bb.ccc.edu 
to produce this:

PHP Code:
S00CBBF.aa.bb 
I need a better understanding.
 
Old 12-05-2007, 04:56 PM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,269

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
Dupe of http://www.linuxquestions.org/questi...t-help-604731/. see my answer there
 
  


Closed Thread


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
script in korn shell disruptive Programming 15 02-22-2007 10:18 AM
korn shell ( ksh ) lechuga Puppy 3 02-05-2007 09:43 PM
Korn shell and Arrays jpc82 Programming 1 06-28-2005 02:27 AM
Korn shell script Muzica Solaris / OpenSolaris 4 09-06-2004 12:47 PM
install korn shell namgor Linux - Newbie 1 07-12-2004 02:52 PM


All times are GMT -5. The time now is 07:50 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration