<?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 checking for multiple user in /etc/passwd file. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/checking-for-multiple-user-in-etc-passwd-file/m-p/6172835#M496097</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to check multiple user registered in server.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a basic script like :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;hostlist=/hometestuser/source&lt;BR /&gt;username=/hometestuser/source&lt;BR /&gt;HOMEDIR=/hometestuser/source&lt;BR /&gt;for HOST in `cat hostlist`&lt;BR /&gt;do&lt;BR /&gt;echo "====================================================" &amp;gt;&amp;gt; ${HOMEDIR}/logfile.txt&lt;BR /&gt;echo "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "&lt;BR /&gt;echo "$HOST" &amp;gt;&amp;gt; ${HOMEDIR}/logfile.txt&lt;BR /&gt;ssh $HOST grep `cat username` /etc/passwd &amp;gt;&amp;gt; ${HOMEDIR}/logfile.txt&lt;BR /&gt;done&lt;BR /&gt;echo "====================================================="&amp;nbsp; &amp;gt;&amp;gt; ${HOMEDIR}/logfile.txt&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;$$$$$$$&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will be getting the username and hostlist from a file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I running for multiple user , I am getting error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;ssh $HOST grep `cat username` /etc/passwd &amp;gt;&amp;gt; ${HOMEDIR}/logfile.txt&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ssh testhost grep ---&amp;gt; it is reading all username in the file as below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ssh testhost grep user1 user2 /etc/passwd&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i want to add -e to grep or need to know any other option is available or not ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 17 Aug 2013 18:57:40 GMT</pubDate>
    <dc:creator>tempsample</dc:creator>
    <dc:date>2013-08-17T18:57:40Z</dc:date>
    <item>
      <title>checking for multiple user in /etc/passwd file.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/checking-for-multiple-user-in-etc-passwd-file/m-p/6172835#M496097</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to check multiple user registered in server.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a basic script like :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;hostlist=/hometestuser/source&lt;BR /&gt;username=/hometestuser/source&lt;BR /&gt;HOMEDIR=/hometestuser/source&lt;BR /&gt;for HOST in `cat hostlist`&lt;BR /&gt;do&lt;BR /&gt;echo "====================================================" &amp;gt;&amp;gt; ${HOMEDIR}/logfile.txt&lt;BR /&gt;echo "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "&lt;BR /&gt;echo "$HOST" &amp;gt;&amp;gt; ${HOMEDIR}/logfile.txt&lt;BR /&gt;ssh $HOST grep `cat username` /etc/passwd &amp;gt;&amp;gt; ${HOMEDIR}/logfile.txt&lt;BR /&gt;done&lt;BR /&gt;echo "====================================================="&amp;nbsp; &amp;gt;&amp;gt; ${HOMEDIR}/logfile.txt&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;$$$$$$$&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will be getting the username and hostlist from a file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I running for multiple user , I am getting error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;ssh $HOST grep `cat username` /etc/passwd &amp;gt;&amp;gt; ${HOMEDIR}/logfile.txt&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ssh testhost grep ---&amp;gt; it is reading all username in the file as below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ssh testhost grep user1 user2 /etc/passwd&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i want to add -e to grep or need to know any other option is available or not ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2013 18:57:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/checking-for-multiple-user-in-etc-passwd-file/m-p/6172835#M496097</guid>
      <dc:creator>tempsample</dc:creator>
      <dc:date>2013-08-17T18:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: checking for multiple user in /etc/passwd file.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/checking-for-multiple-user-in-etc-passwd-file/m-p/6172855#M496099</link>
      <description>&lt;P&gt;There are several problems with the concept. First, grep must always be protected from finding the wrong matches. If you have a username of &lt;STRONG&gt;bill&lt;/STRONG&gt;, then it will find every line where usernames like &lt;STRONG&gt;bill&lt;/STRONG&gt;, &lt;STRONG&gt;billy&lt;/STRONG&gt;, &lt;STRONG&gt;waybill&lt;/STRONG&gt;, &lt;STRONG&gt;billh&lt;/STRONG&gt;, etc are located, but worse, grep doesn't stop at the username -- it will match comments, even a home directory like &lt;STRONG&gt;/home/billing&lt;/STRONG&gt; or &lt;STRONG&gt;/home/dashbill&lt;/STRONG&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So start by testing your grep locally. To match just the username (which always starts in column 1), anchor the search to the beginning of each line:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;grep ^bill /etc/passwd&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;But that is not enough. grep will still find &lt;STRONG&gt;bill&lt;/STRONG&gt; and &lt;STRONG&gt;billh&lt;/STRONG&gt; which are not duplicates. So extend the search to the mandatory colon (:) at the end of the name, like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;grep ^bill: /etc/passwd&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now for multiple matches, the -e works fine, or you an use egrep with extended regular expressions but I find the multiple bars and extra quotes a bit confusing read when checking scripts. &amp;nbsp;Here are both ways:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;grep -e ^bill: -e ^joe: -e ^mary: -e ^jennifer: /etc/passwd

egrep  "^bill:|^joe:|^mary:|^jennifer:" /etc/passwd&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now creating a grep pattern list like this is a bit tricky but can be done.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the question is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are you looking for duplicate user names or duplicate user ID numbers?&lt;/P&gt;&lt;P&gt;For duplicate usernames, you can do something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;cut -d: -f1 /etc/passwd | sort | uniq -c
or 
cut -d: -f1 /etc/passwd | sort | uniq -c | grep -v " 1 "
(shows only duplicate usernames)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;But to find duplicate user ID's (UID), just run:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;logins -d&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2013 20:23:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/checking-for-multiple-user-in-etc-passwd-file/m-p/6172855#M496099</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2013-08-17T20:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: checking for multiple user in /etc/passwd file.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/checking-for-multiple-user-in-etc-passwd-file/m-p/6172875#M496100</link>
      <description>&lt;P&gt;&amp;gt;hostlist=/hometestuser/source&lt;BR /&gt;&amp;gt;username=/hometestuser/source&lt;BR /&gt;&amp;gt;HOMEDIR=/hometestuser/source&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Should this be:&lt;/P&gt;&lt;P&gt;hostlist=${HOMEDIR}/hostlist?&lt;/P&gt;&lt;P&gt;username=${HOMEDIR}/username?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;for HOST in `cat hostlist`; do&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To remove evil cats, change to:&lt;/P&gt;&lt;P&gt;for HOST in $(&amp;lt; $hostlist); do&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If every output is to the same file, you can redirect the whole for loop:&lt;BR /&gt;&amp;nbsp;&amp;nbsp; echo "===================================================="&lt;BR /&gt;&amp;nbsp;&amp;nbsp; echo "$HOST"&lt;BR /&gt;&amp;nbsp;&amp;nbsp; ssh $HOST grep $(&amp;lt; $username) /etc/passwd&lt;BR /&gt;done &amp;gt;&amp;gt; ${HOMEDIR}/logfile.txt&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: The above grep is going to get ALL of the names on one line and that won't work.&amp;nbsp; You can use -f file but then that file must be on $HOST.&amp;nbsp; Bill mentioned creating multiple "-e name" patterns on the command line.&amp;nbsp; But it may be easier to just copy the /etc/passwd file back to this machine to process.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; scp $host:/etc/passwd passwd.${HOST}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; grep -f $username passwd.${HOST}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But based on Bill's comments, you should have the anchors already in $username:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ^joe:&lt;/P&gt;&lt;P&gt;&amp;nbsp; ^sam:&lt;/P&gt;&lt;P&gt;You can of course process the original file and create a temp file with that format:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; sed -e 's/\(.*\)/^\1:/' $username &amp;gt; $username.tmp&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;For duplicate usernames, you can do something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Except for logins(1m), those cut(1) commands would work better on the passwd copied back to the source machine.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2013 21:16:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/checking-for-multiple-user-in-etc-passwd-file/m-p/6172875#M496100</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2013-08-17T21:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: checking for multiple user in /etc/passwd file.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/checking-for-multiple-user-in-etc-passwd-file/m-p/6173169#M496101</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks Bill and Dennis for suggestion.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;from your comment , I can understand that ,in&amp;nbsp; username file i have to add -e&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;some thing like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;cat username&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-e user1&lt;/P&gt;&lt;P&gt;-e user2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or I have to use some anchor .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but my requirement is , In username file it should be in the below format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;cat username&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;user1&lt;/P&gt;&lt;P&gt;user2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Aug 2013 17:01:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/checking-for-multiple-user-in-etc-passwd-file/m-p/6173169#M496101</guid>
      <dc:creator>tempsample</dc:creator>
      <dc:date>2013-08-18T17:01:10Z</dc:date>
    </item>
    <item>
      <title>Re: checking for multiple user in /etc/passwd file.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/checking-for-multiple-user-in-etc-passwd-file/m-p/6173249#M496102</link>
      <description>&lt;P&gt;&amp;gt;In username file it should be in the below format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My above post showed you how to use sed to change the file format.&amp;nbsp; A slight modification will add -e and anchors:&lt;/P&gt;&lt;P&gt;grep $(sed 's/\(.*\)/-e ^\1:/' $username) passwd.${HOST}&lt;/P&gt;</description>
      <pubDate>Sun, 18 Aug 2013 18:33:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/checking-for-multiple-user-in-etc-passwd-file/m-p/6173249#M496102</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2013-08-18T18:33:52Z</dc:date>
    </item>
  </channel>
</rss>

