- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Scripting
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2006 09:56 PM
06-22-2006 09:56 PM
1)We want to move our entries from the /etc/hosts file to Windows DNS . We have got nearly 700 entries in the host file and only few exists in the Windows DNS.Without a script I will have to manually check if the entry is present in the DNS,if it is then delete from the host file and if it is not in DNS then add the entry on Windows Server and delete it from the /etc/hosts file.
I wanted to write a script which specifies any entries in the HOSTS file that are NOT present on the DNS server and the script must check both forward and reverse lookup
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2006 10:03 PM
06-22-2006 10:03 PM
Re: Scripting
HP-UY provides a program 'host_to_named' - check its man page. It should be the starting point for your script, if it should be not possible to do all your stuff via that.
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2006 10:12 PM
06-22-2006 10:12 PM
SolutionPlease use the following script
#!/usr/bin/ksh
egrep -v "^#|^$" /etc/hosts | awk '{print $1,$2}' | while read ipaddr hostnm rest
do
nslookupip=$(nslookup $hostnm 2>/dev/null | awk '/Trying DNS/,/zzz/' | grep -i address | awk '{print $NF}')
if [[ -z $nslookupip ]]
then
echo "NO ENTRY in DNS for $hostnm" >> newhosts.log
else
if [[ "$ipaddr" = "$nslookupip" ]]
then
echo "VALID ENTRY for $hostnm in DNS" >> newhosts.log
fi
fi
done
which I have modified a bit for your case. I had suggested this for the following thread http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1036190
You can filter the entries not in DNS by
grep 'NO ENTRY' newhosts.log
Regards,
Ninad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2006 11:54 PM
06-22-2006 11:54 PM
Re: Scripting
I modified Ninad's script to do reverse DNS, as well. I hope you don't mind, Ninad.
Here it is:
#!/usr/bin/ksh
cat /dev/null > newhosts_rev.log
ns=$(awk '/nameserver/ {print $2; exit}' /etc/resolv.conf)
egrep -v "^#|^$" /etc/hosts | awk '{print $1,$2}' | while read ipaddr hostnm rest
do
nslookupnm=$(nslookup $ipaddr $ns 2>/dev/null | \
awk '/Trying DNS/,/zzz/' | grep 'Name' | awk '{print $NF}')
echo $nslookupnm
if [[ -z $nslookupnm ]]
then
echo "NO REVERSE ENTRY for $ipaddr ($hostnm)" >> newhosts_rev.log
else
hostnm=$(echo $hostnm | cut -d. -f1)
nslookupnm=$(echo $nslookupnm | cut -d. -f1)
if [[ "$hostnm" = "$nslookupnm" ]]
then
echo "VALID REVERSE ENTRY for $ipaddr ($hostnm)" >> newhosts_rev.log
fi
fi
done
The nameserver is taken from /etc/resolv.conf and passed as an argument to nslookup. This prevents nslookup from looking at /etc/hosts for entries.
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2006 12:39 AM
06-23-2006 12:39 AM
Re: Scripting
Can you please suggest me a book for Korn Scripting.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2006 12:46 AM
06-23-2006 12:46 AM
Re: Scripting
A free quick-start to shells can be found here:
http://docs.hp.com/en/B2355-90046/B2355-90046.pdf
I would urge you to use the Posix shell for HP-UX. This is the HP standard shell and *required* to be 'root's default shell. THe Posix shell is almost identical to the Korn shell, although the modern Korn shells do offer some nice features not yet present.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2006 01:06 AM
06-23-2006 01:06 AM
Re: Scripting
Hands down my favorite guide to scripting is "Shells: User's Guide: HP 9000 Computers", available at:
http://docs.hp.com/en/B2355-90046/
Korn is covered, along with others. I would urge you to use the POSIX shell, as it is the standard, and almost identical to ksh.
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2006 02:45 AM
06-23-2006 02:45 AM