<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Need scripting help in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387663#M198722</link>
    <description>I got your problem that you are not copying the lines /etc/hosts files with count 1 to temporary file so that it is making problem there.&lt;BR /&gt;&lt;BR /&gt;Try this script,&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;# Debugging mode&lt;BR /&gt;set -x&lt;BR /&gt;&lt;BR /&gt;#### Log files ######&lt;BR /&gt;LOG=/var/host.log&lt;BR /&gt;DUFF=/usr8/hosts.duff&lt;BR /&gt;GOOD=/usr8/hosts.good&lt;BR /&gt;&lt;BR /&gt;# hosts files copy #&lt;BR /&gt;cp /etc/hosts $DUFF&lt;BR /&gt;cp /etc/hosts /etc/hosts.def&lt;BR /&gt;&lt;BR /&gt;# Create a new file if exits delete and create&lt;BR /&gt;[[ -f $GOOD ]] &amp;amp;&amp;amp; rm -f $GOOD&lt;BR /&gt;touch $GOOD&lt;BR /&gt;&lt;BR /&gt;# Duplication check&lt;BR /&gt;cat $DUFF | while read line&lt;BR /&gt;do&lt;BR /&gt;&lt;BR /&gt;if [[ `grep "$line" $DUFF | wc -l` -gt 1 &amp;amp;&amp;amp; `grep "$line" $GOOD | wc -l` -eq 0 ]]&lt;BR /&gt;then&lt;BR /&gt;echo "Duplicate entry $line in host file" &amp;gt;&amp;gt; $LOG&lt;BR /&gt;echo "$line" &amp;gt;&amp;gt; $GOOD&lt;BR /&gt;elif [[ `grep "$line" $DUFF | wc -l` -eq 1 &amp;amp;&amp;amp; `grep "$line" $GOOD | wc -l` -eq 0 ]]&lt;BR /&gt;then&lt;BR /&gt;echo "$line" &amp;gt;&amp;gt; $GOOD&lt;BR /&gt;else&lt;BR /&gt;echo "Found the entry in the good host file, loop has completed." &amp;gt;&amp;gt; $LOG&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;# Copy to hosts file&lt;BR /&gt;cp $GOOD /etc/hosts&lt;BR /&gt;chmod 444 /etc/hosts&lt;BR /&gt;&lt;BR /&gt;It will work now. &lt;BR /&gt;&lt;BR /&gt;Note: While your are operating on system files as like /etc/hosts without proper check don't operate there as,&lt;BR /&gt;cp $GOOD /etc/hosts&lt;BR /&gt;chmod 444 /etc/hosts&lt;BR /&gt;&lt;BR /&gt;it will make that $GOOD files to be copied to /etc/hosts so that no entries will be there in /etc/hosts file too.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;In My script I am using as,&lt;BR /&gt;cp /etc/hosts /etc/hosts.def&lt;BR /&gt;so that default will be there in /etc/hosts.def to get it for ever in future :-)&lt;BR /&gt;&lt;BR /&gt;HTH.&lt;BR /&gt;</description>
    <pubDate>Mon, 27 Sep 2004 11:39:26 GMT</pubDate>
    <dc:creator>Muthukumar_5</dc:creator>
    <dc:date>2004-09-27T11:39:26Z</dc:date>
    <item>
      <title>Need scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387652#M198711</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;This a script was put out by one of my colleagues (honest) which did a sed and replaced an old hostname with a new host name for a server. However, it had to do this 9 times.  This was done in individuial loops and the results &amp;gt;&amp;gt; to a new host file.  The problem occured now in that we have 9 entries for each IP in /etc/hosts.&lt;BR /&gt;&lt;BR /&gt;I have written a simple script to perform a check against each entry and then out put it to a new host file, however, I have found in some circumetances particualr lines on /etc/hosts are not picked up with a grep.&lt;BR /&gt;&lt;BR /&gt;My script is attached. Any ideas how Icabn make sure it picks up each line when i perform `cat file | while read line` ??&lt;BR /&gt;Any ideas !?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 27 Sep 2004 09:30:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387652#M198711</guid>
      <dc:creator>Paul Thomson_2</dc:creator>
      <dc:date>2004-09-27T09:30:30Z</dc:date>
    </item>
    <item>
      <title>Re: Need scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387653#M198712</link>
      <description>Nothing is attached.&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Mon, 27 Sep 2004 09:34:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387653#M198712</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2004-09-27T09:34:54Z</dc:date>
    </item>
    <item>
      <title>Re: Need scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387654#M198713</link>
      <description>you can use awk '/xxxxx/' instead of grep . It is quite useful</description>
      <pubDate>Mon, 27 Sep 2004 09:37:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387654#M198713</guid>
      <dc:creator>jpcast_real</dc:creator>
      <dc:date>2004-09-27T09:37:00Z</dc:date>
    </item>
    <item>
      <title>Re: Need scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387655#M198714</link>
      <description>Will try attachment now !</description>
      <pubDate>Mon, 27 Sep 2004 09:38:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387655#M198714</guid>
      <dc:creator>Paul Thomson_2</dc:creator>
      <dc:date>2004-09-27T09:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: Need scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387656#M198715</link>
      <description>do sh -x &amp;lt;scriptname&amp;gt; and follow each line. &lt;BR /&gt;this is sort of debugging, but this will help you in knowing each line output. &lt;BR /&gt;&lt;BR /&gt;Prashant</description>
      <pubDate>Mon, 27 Sep 2004 09:46:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387656#M198715</guid>
      <dc:creator>Prashant Zanwar_4</dc:creator>
      <dc:date>2004-09-27T09:46:44Z</dc:date>
    </item>
    <item>
      <title>Re: Need scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387657#M198716</link>
      <description>We can debug script with set -x to find problem easily,&lt;BR /&gt;&lt;BR /&gt; -- your script ---&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;## Debugging &lt;BR /&gt;##  set -x &lt;BR /&gt;LOG=/var/host.log&lt;BR /&gt;DUFF=/usr8/hosts.duff&lt;BR /&gt;GOOD=/usr8/hosts.good&lt;BR /&gt;cp /etc/hosts $DUFF&lt;BR /&gt;touch $GOOD&lt;BR /&gt;cat $DUFF | while read line&lt;BR /&gt;do&lt;BR /&gt;sleep 1&lt;BR /&gt;if&lt;BR /&gt;[ `grep "$line" $DUFF | wc -l` -gt 1 ] &amp;amp;&amp;amp; [ `grep "$line" $GOOD | wc -l&lt;BR /&gt;` = 0 ]&lt;BR /&gt;then&lt;BR /&gt;echo "Duplicate entry in host file" &amp;gt;&amp;gt; $LOG&lt;BR /&gt;echo "$line" &amp;gt;&amp;gt; $GOOD&lt;BR /&gt;else&lt;BR /&gt;echo "Found the entry in the good host file, loop has completed." &amp;gt;&amp;gt; $LOG&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;cp $GOOD /etc/hosts&lt;BR /&gt;chmod 444 /etc/hosts&lt;BR /&gt;&lt;BR /&gt;Your are using ir-required logic's here. Good file will not be containing any entries why you are checkign there with duff file there??&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;There is no action done to change the hostname there in your script.&lt;BR /&gt;&lt;BR /&gt;To change your hostname use sed / awk / perl program there.&lt;BR /&gt;&lt;BR /&gt;IF you want to get duplication on /etc/hosts file then,&lt;BR /&gt;&lt;BR /&gt; cp /etc/hosts /tmp/hosts&lt;BR /&gt;&lt;BR /&gt; grep -vf /etc/hosts /tmp/hosts &lt;BR /&gt; will give duplication entries there.</description>
      <pubDate>Mon, 27 Sep 2004 09:49:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387657#M198716</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-09-27T09:49:56Z</dc:date>
    </item>
    <item>
      <title>Re: Need scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387658#M198717</link>
      <description>`grep "$line" $GOOD | wc -l&lt;BR /&gt;` = 0 ]&lt;BR /&gt;may read "`grep "$line" $GOOD | wc -l&lt;BR /&gt;` -eq 0 ]&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;Jean-Luc</description>
      <pubDate>Mon, 27 Sep 2004 09:50:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387658#M198717</guid>
      <dc:creator>Jean-Luc Oudart</dc:creator>
      <dc:date>2004-09-27T09:50:56Z</dc:date>
    </item>
    <item>
      <title>Re: Need scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387659#M198718</link>
      <description>Muthukumar&lt;BR /&gt;&lt;BR /&gt;My check for good file, is when it finds a line the next time it finds a duplicate entry the line will be in the good file so it will not echo $line again&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 27 Sep 2004 10:01:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387659#M198718</guid>
      <dc:creator>Paul Thomson_2</dc:creator>
      <dc:date>2004-09-27T10:01:32Z</dc:date>
    </item>
    <item>
      <title>Re: Need scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387660#M198719</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;Sorry, Im quite happy with the content of the script,as it does what it is supposed to.&lt;BR /&gt;&lt;BR /&gt;But some entries in hosts are not picked up by grep "$line" /etc/hosts and I wondered why ? OR if anyone knew a better method. I have tried awk too on the same line and it cant find it either....&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 27 Sep 2004 10:04:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387660#M198719</guid>
      <dc:creator>Paul Thomson_2</dc:creator>
      <dc:date>2004-09-27T10:04:47Z</dc:date>
    </item>
    <item>
      <title>Re: Need scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387661#M198720</link>
      <description>sort input-file | uniq &amp;gt; output-file</description>
      <pubDate>Mon, 27 Sep 2004 10:27:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387661#M198720</guid>
      <dc:creator>Bob Smith_23</dc:creator>
      <dc:date>2004-09-27T10:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: Need scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387662#M198721</link>
      <description>I have used your script and tried your requirement so that,&lt;BR /&gt;&lt;BR /&gt;the problem is because of if loop check there as,&lt;BR /&gt;&lt;BR /&gt;if&lt;BR /&gt;[ `grep "$line" $DUFF | wc -l` -gt 1 ] &amp;amp;&amp;amp; [ `grep "$line" $GOOD | wc -l&lt;BR /&gt;` = 0 ]&lt;BR /&gt;&lt;BR /&gt;while checking number then use -eq or -ne etc there as,&lt;BR /&gt;&lt;BR /&gt;if&lt;BR /&gt;[ `grep "$line" $DUFF | wc -l` -gt 1 ] &amp;amp;&amp;amp; [ `grep "$line" $GOOD | wc -l&lt;BR /&gt;` -eq 0 ]&lt;BR /&gt;&lt;BR /&gt;but any way it will be checking that,&lt;BR /&gt;&lt;BR /&gt; 1&amp;gt; line contains in the file more than once  or line must not be there in good file.&lt;BR /&gt;&lt;BR /&gt; so that it will add the contents to good file there.&lt;BR /&gt;&lt;BR /&gt; your script is not checking duplicated liens which they located two lines later, etc there.&lt;BR /&gt;</description>
      <pubDate>Mon, 27 Sep 2004 11:09:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387662#M198721</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-09-27T11:09:30Z</dc:date>
    </item>
    <item>
      <title>Re: Need scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387663#M198722</link>
      <description>I got your problem that you are not copying the lines /etc/hosts files with count 1 to temporary file so that it is making problem there.&lt;BR /&gt;&lt;BR /&gt;Try this script,&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;# Debugging mode&lt;BR /&gt;set -x&lt;BR /&gt;&lt;BR /&gt;#### Log files ######&lt;BR /&gt;LOG=/var/host.log&lt;BR /&gt;DUFF=/usr8/hosts.duff&lt;BR /&gt;GOOD=/usr8/hosts.good&lt;BR /&gt;&lt;BR /&gt;# hosts files copy #&lt;BR /&gt;cp /etc/hosts $DUFF&lt;BR /&gt;cp /etc/hosts /etc/hosts.def&lt;BR /&gt;&lt;BR /&gt;# Create a new file if exits delete and create&lt;BR /&gt;[[ -f $GOOD ]] &amp;amp;&amp;amp; rm -f $GOOD&lt;BR /&gt;touch $GOOD&lt;BR /&gt;&lt;BR /&gt;# Duplication check&lt;BR /&gt;cat $DUFF | while read line&lt;BR /&gt;do&lt;BR /&gt;&lt;BR /&gt;if [[ `grep "$line" $DUFF | wc -l` -gt 1 &amp;amp;&amp;amp; `grep "$line" $GOOD | wc -l` -eq 0 ]]&lt;BR /&gt;then&lt;BR /&gt;echo "Duplicate entry $line in host file" &amp;gt;&amp;gt; $LOG&lt;BR /&gt;echo "$line" &amp;gt;&amp;gt; $GOOD&lt;BR /&gt;elif [[ `grep "$line" $DUFF | wc -l` -eq 1 &amp;amp;&amp;amp; `grep "$line" $GOOD | wc -l` -eq 0 ]]&lt;BR /&gt;then&lt;BR /&gt;echo "$line" &amp;gt;&amp;gt; $GOOD&lt;BR /&gt;else&lt;BR /&gt;echo "Found the entry in the good host file, loop has completed." &amp;gt;&amp;gt; $LOG&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;# Copy to hosts file&lt;BR /&gt;cp $GOOD /etc/hosts&lt;BR /&gt;chmod 444 /etc/hosts&lt;BR /&gt;&lt;BR /&gt;It will work now. &lt;BR /&gt;&lt;BR /&gt;Note: While your are operating on system files as like /etc/hosts without proper check don't operate there as,&lt;BR /&gt;cp $GOOD /etc/hosts&lt;BR /&gt;chmod 444 /etc/hosts&lt;BR /&gt;&lt;BR /&gt;it will make that $GOOD files to be copied to /etc/hosts so that no entries will be there in /etc/hosts file too.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;In My script I am using as,&lt;BR /&gt;cp /etc/hosts /etc/hosts.def&lt;BR /&gt;so that default will be there in /etc/hosts.def to get it for ever in future :-)&lt;BR /&gt;&lt;BR /&gt;HTH.&lt;BR /&gt;</description>
      <pubDate>Mon, 27 Sep 2004 11:39:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-scripting-help/m-p/3387663#M198722</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-09-27T11:39:26Z</dc:date>
    </item>
  </channel>
</rss>

