Korn Shell and Perl Administrative Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Korn Shell and Perl Administrative Script
# 1  
Old 12-13-2007
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
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl script to korn shell script

I have a perl script which replaces "*" with "|" and "~" with "\n" also it takes the file content starting with ST till record starting with SE written a differnet file, I wanted this to be convereted into KSH script, can anyone help me perl script: perl -e ' $file_counter=0;... (7 Replies)
Discussion started by: atlantis_yy
7 Replies

2. UNIX for Advanced & Expert Users

Calling PERL from a Korn shell script

I am currently in Afghanistan and do not have access to some of the resources I normally do back in the US. Just accessed this site and it looks promising! Hopefully you will not find my question too much of a waste of your time. I write mostly Korn Shell and PERL on Solaris systems for the... (2 Replies)
Discussion started by: mseanowen
2 Replies

3. Shell Programming and Scripting

pass null value to sql script from korn shell script

There are 4 parameters that I have to pass from korn shell to sql script. 1) I have to check if $1 , $2 , $3 and $4 are null values or not . How can I do that ? 2) Once its determined that these values are null (in the sense they are empty) how can I pass null values to sql script... (11 Replies)
Discussion started by: megha2525
11 Replies

4. Shell Programming and Scripting

HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

Hi all, Not sure if this should be in the programming forum, but I believe it will get more response under the Shell Programming and Scripting FORUM. Am trying to write a customized df script in Perl and need some help with regards to using arrays and file handlers. At the moment am... (3 Replies)
Discussion started by: newbie_01
3 Replies

5. Homework & Coursework Questions

Korn Shell Script

1. The problem statement, all variables and given/known data: Write a korn shell script with an alfanumeric string as argument. The script lists the file's names in the current directory that contain the given string as substring and that can be read and written. 2. Relevant commands, code,... (3 Replies)
Discussion started by: burm
3 Replies

6. Shell Programming and Scripting

Korn Shell Script

I have to solve some exercises in Korn Shell, but i'm having some problems. For example: Write a korn shell script with an alfanumeric string as argument. The script lists the file's names in the current directory that contain the given string as substring and that can be read and written. I... (3 Replies)
Discussion started by: burm
3 Replies

7. AIX

Help with Korn Shell script

I have this Korn shell script that runs via a cron entry. It runs in a loop "watching" a specific file system for files with a certain name. The file system that it is watching is an upload file system for an FTP server. When files that are the correct name come in, it takes the extension of the... (1 Reply)
Discussion started by: heprox
1 Replies

8. UNIX Desktop Questions & Answers

korn shell script

hi all i am writing the korn shell script. i have a SQL script which gives me the folowing output DSA.WLG.20050713211544.20051025.20050713211544 28991 1130198400 DSA.WLG.20050713211544.20051025.20050713211544 25881 1130198400 DSA.WLG.20050711210100.20051025.20050711210100 25881 ... (3 Replies)
Discussion started by: pavan_test
3 Replies

9. UNIX for Dummies Questions & Answers

korn shell script

hello., i have 2 files.. 1 file is in this folder /home/test/ssk/DSA.WLG.20050713211544.20050710.20050713211544 (this part) other file is in this folder /home/kk/dev/DSA.WLG.20050711210100.20050710.20050711210100 ... (1 Reply)
Discussion started by: pavan_test
1 Replies
Login or Register to Ask a Question