The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Korn shell interactive script leonard905 Shell Programming and Scripting 3 08-02-2007 03:16 PM
Help with Korn Shell script heprox AIX 1 12-19-2005 02:04 PM
korn shell script pavan_test UNIX Desktop for Dummies Questions & Answers 3 10-27-2005 01:09 PM
korn shell script pavan_test UNIX for Dummies Questions & Answers 1 10-26-2005 02:17 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-13-2007
metallica1973 metallica1973 is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 19
Korn Shell and Perl Administrative Script

I have this script that I want to be able to scan a list of IP address from a file (namlist and snifflist)and Hostnames of network devices to see if they are alive or down and if telnet port 23 is open. I originally started to write this in Korn Shell and ran into some issue trying to closed a telnet probe. So I was told to try Perl which I know nothing of and I am a very basic programmer with no backround in programming as well. Here is my script:

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

$NAMFILE 
$SNIFFILE 
$OUT 

echo       Daily Sniffer and NAMs Scan as of - `date` >> $OUT 
echo     >> $OUT 
echo       There is a 8 sec timeout of devices  >> $OUT 

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

printf 
" %-15.20s %-8s %-6s \n" NAM Status Telnet >> $NAMFILE 

echo " ===============================" >>$NAMFILE 
for NAM in $(<namlist

do 
        
Status=down 
        Telnet
=closed 
        
if ping $NAM 5 >/dev/null 2>&
        then 
                Status
=up 
                Telnet
=$(perl -e  'use IO::Socket; print new IO::Socket::INET (PeerAddr => "'$SNIFFERS'", PeerPort => "23", Timeout => 5 
 ) ? "open\n" : "closed\n";'

                
READPID=$! 
               
# sleep 15 
                
if ps awk '{print $1}' grep $READPID 2>/dev/null 
                then 
                        Telnet
="open" 
                        
kill $READPID 
                fi 
                printf 
" %-15.20s %-8s %-6s \n" $NAM $Status $Telnet >> $NAMFILE 
        
else 
                
Telnet="n/a" 
                
printf " %-15.20s %-8s %-6s \n" $NAM $Status $Telnet >> $NAMFILE 
        fi 

done 

echo >> $SNIFFILE 

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

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

for SNIFFERS in $(<snifflist

do 
        
TRUNCSNIF=$(echo $SNIFFERS awk -F'.' '{for (i=1;i<=NF-2;i++) {if (i<NF-2) printf $i"."; else print $i}}'
        
Status=down 
        Telnet
=closed 
        
if ping $SNIFFERS 5 >/dev/null 2>&
        then 
           Status
=up 
                Telnet
=$(perl -e  'use IO::Socket; print new IO::Socket::INET (PeerAddr => "'$SNIFFERS'", PeerPort => "23", Timeout =>5 
) ? "open\n" : "closed\n";'

                
READPID=$! 
                
sleep 15 
                
if ps awk '{print $1}' grep $READPID 2>/dev/null 
                then 
                        Telnet
="open" 
                        
kill $READPID 
                fi 

                IP_Addr
="$(nslookup $SNIFFERS | tail -3 | grep '^Address:' | awk '{print $2}')" 
                
IP_Address="$IP_Addr" 
                
[[ -"$IP_Address" ]] && IP_Address="n/a" 
                
printf " %-15.20s %-15.20s %-8s %-6s \n" $TRUNCSNIF $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" $TRUNCSNIF $IP_Address $Status $Telnet >>$SNIFFILE 

        fi 

done 

cat $NAMFILE $SNIFFILE 
>> $OUT 
mailx 
-s"Daily NAM and Sniffer Report" $MAIL_LIST $OUT 
Here is what I have tested

PHP Code:
bash-3.00perl -e  'use IO::Socket; print new IO::Socket::INET (PeerAddr => "'192.18.158.17'", PeerPort => "23", ) ? "closed\n" : "open\n";' 
and here is the output that it always give me, a closed port when I know that it is open.

PHP Code:
closed 
This is the part that I do not understand

PHP Code:
"open\n" "closed\n"
from

PHP Code:
Telnet=$(perl -e  'use IO::Socket; print new IO::Socket::INET (PeerAddr => "'$SNIFFERS'", PeerPort => "23", Timeout =>5   ) ? "open\n" : "closed\n";'
Help
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0