![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| check ssh connection to remote host | praveenbvarrier | Shell Programming and Scripting | 6 | 10-06-2008 09:46 AM |
| Duplicate crontab entries | vikashtulsiyan | SUN Solaris | 2 | 05-06-2008 02:07 AM |
| Bash Script to check Remote Host Connection | zulfikarmd | UNIX for Dummies Questions & Answers | 5 | 04-16-2008 03:53 AM |
| Filtering multiple entries in a file | suman_jakkula | Shell Programming and Scripting | 2 | 08-22-2006 02:02 AM |
| deleting double entries in a log file | opusforum | Shell Programming and Scripting | 5 | 09-17-2002 12:02 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Check host file for duplicate entries
I need a KSH script that will check a host file for duplicate IP's and/or host names and report out the errors. Anyone out there have one they would like to share?
Something like: Hostname blahblah appears X times IP Address xxx.xxx.xxx.xxx appears X times TIA |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Hacking a previous post, something along the lines of
for i in `cat /etc/hosts | cut -d"." -f1,2 | uniq` do num=`cat /etc/hosts | grep $i | wc -l` if (( $num > 1 )) then echo $i fi done which will show you the IP address that have duplicates I think, just needs polishing off with a ''wc' command ? - someone please confirm - digging up my script memories! ------------------------------------------------------------------- ~ stevie Solaris SCSA (v8) Microsoft MCP Ubuntu & Fedora on-the-way |
|
#3
|
|||
|
|||
|
hmmmm, maybe
uniq only picks up repeats when they are consecutive lines (I think). I need the script to check the whole file for a repeat....
<---scratching head |
|
#4
|
||||
|
||||
|
Code:
getent hosts | awk '{ ip[$1]++
for ( host=2; host <= NF; host++ ) {
hosts[$host] ++
}
}
END {
for ( add in ip ) {
print add, ip[add], "times"
}
for ( h in hosts ) {
print h, hosts[h], "times"
}
}'
|
|
#5
|
|||
|
|||
|
Thank you both for your help, I have it now
Last edited by ThreeDot; 01-22-2008 at 10:43 AM. Reason: question answered |
|||
| Google The UNIX and Linux Forums |