LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Globbing using Korn Shell (https://www.linuxquestions.org/questions/programming-9/globbing-using-korn-shell-604725/)

metallica1973 12-05-2007 01:26 PM

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.

chrism01 12-05-2007 05:56 PM

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


All times are GMT -5. The time now is 08:15 PM.