<?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: Test in script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/test-in-script/m-p/3722609#M253152</link>
    <description>Hi:&lt;BR /&gt;&lt;BR /&gt;If you enclose the variable you are testing in double quotes you will avoid the error "A test command parameter is not valid" when the variable is empty.&lt;BR /&gt;&lt;BR /&gt;The other essential problem with the logic you wrote is that 'finger'ing a valid user returns more than one line of output.&lt;BR /&gt;&lt;BR /&gt;You could amend your script to something along these lines:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;while true&lt;BR /&gt;do&lt;BR /&gt;echo "Enter the user name"&lt;BR /&gt;read USER&lt;BR /&gt;[ -z "${USER}" ] &amp;amp;&amp;amp; continue&lt;BR /&gt;X=`finger $USER |head -1|cut -d ":" -f3`&lt;BR /&gt;if [ "${X}" = " ???" ]&lt;BR /&gt;then &lt;BR /&gt;echo "No such user please try again" &lt;BR /&gt;else&lt;BR /&gt;echo "(ok)"&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Wed, 01 Feb 2006 20:16:03 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2006-02-01T20:16:03Z</dc:date>
    <item>
      <title>Test in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-in-script/m-p/3722607#M253150</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;i am using the following syntext for checking a condition.&lt;BR /&gt;&lt;BR /&gt;echo "Enter the user name"&lt;BR /&gt;read USER&lt;BR /&gt;X=`finger $USER |grep "In real life" |cut -d ":" -f3`&lt;BR /&gt;if test $X = "???"&lt;BR /&gt; then &lt;BR /&gt;  echo "No such user please try again" &lt;BR /&gt; else&lt;BR /&gt;  echo "Enter the login name"&lt;BR /&gt;  read LNAME&lt;BR /&gt;&lt;BR /&gt;While there is no user ie the condition is true it works fine but when i enter a valid user name it works but puts a screen output &lt;BR /&gt;&lt;BR /&gt;./menu.sh[25]: Ayub: A test command parameter is not valid.&lt;BR /&gt;&lt;BR /&gt;How can i resolve this.</description>
      <pubDate>Wed, 01 Feb 2006 19:36:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-in-script/m-p/3722607#M253150</guid>
      <dc:creator>Khashru</dc:creator>
      <dc:date>2006-02-01T19:36:30Z</dc:date>
    </item>
    <item>
      <title>Re: Test in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-in-script/m-p/3722608#M253151</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;a) A user can be perfectly valid and not&lt;BR /&gt;have the GECOS filed set up&lt;BR /&gt;(the fifth coma-separated field in the&lt;BR /&gt;standard password file).&lt;BR /&gt;&lt;BR /&gt;Hence, finger(1) can give you a VERY WRONG&lt;BR /&gt;answer.&lt;BR /&gt;&lt;BR /&gt;We have lot of sites that for one reason or other have no GECOS fields for certain&lt;BR /&gt;usernames.&lt;BR /&gt;&lt;BR /&gt;b) If the username is valid you are asking&lt;BR /&gt;for another input in your script&lt;BR /&gt;("read LNAME"). There is no need for it.&lt;BR /&gt;&lt;BR /&gt;c) Otherwise, if you are not using Trusted Systems password database, it is easier to &lt;BR /&gt;rely on the password file. The data that you &lt;BR /&gt;are extracting via finger(1) are actually the fifth coma-seperated field in the password record.&lt;BR /&gt;&lt;BR /&gt;Something like this (wrote and tested in less that a minute):&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;echo "Enter the user name"&lt;BR /&gt;read USER&lt;BR /&gt;&lt;BR /&gt;X=`awk -F: '{if ($1 == "'$USER'") print}' /etc/passwd`&lt;BR /&gt;GECOS=`echo $X | awk -F: '{print $5}'`&lt;BR /&gt;&lt;BR /&gt;if ! test "$X"&lt;BR /&gt;then&lt;BR /&gt;        echo "No such user please try again"&lt;BR /&gt;else&lt;BR /&gt;        echo "Valid user $USER"&lt;BR /&gt;        if test "$GECOS"&lt;BR /&gt;        then&lt;BR /&gt;                print "User $USER described as \"$GECOS\""&lt;BR /&gt;        else&lt;BR /&gt;                print "User $USER not listed in password file GECOS"&lt;BR /&gt;        fi&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Dusan</description>
      <pubDate>Wed, 01 Feb 2006 20:12:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-in-script/m-p/3722608#M253151</guid>
      <dc:creator>VK2COT</dc:creator>
      <dc:date>2006-02-01T20:12:05Z</dc:date>
    </item>
    <item>
      <title>Re: Test in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-in-script/m-p/3722609#M253152</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;If you enclose the variable you are testing in double quotes you will avoid the error "A test command parameter is not valid" when the variable is empty.&lt;BR /&gt;&lt;BR /&gt;The other essential problem with the logic you wrote is that 'finger'ing a valid user returns more than one line of output.&lt;BR /&gt;&lt;BR /&gt;You could amend your script to something along these lines:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;while true&lt;BR /&gt;do&lt;BR /&gt;echo "Enter the user name"&lt;BR /&gt;read USER&lt;BR /&gt;[ -z "${USER}" ] &amp;amp;&amp;amp; continue&lt;BR /&gt;X=`finger $USER |head -1|cut -d ":" -f3`&lt;BR /&gt;if [ "${X}" = " ???" ]&lt;BR /&gt;then &lt;BR /&gt;echo "No such user please try again" &lt;BR /&gt;else&lt;BR /&gt;echo "(ok)"&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 01 Feb 2006 20:16:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-in-script/m-p/3722609#M253152</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-02-01T20:16:03Z</dc:date>
    </item>
    <item>
      <title>Re: Test in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-in-script/m-p/3722610#M253153</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I am using a trusted system. how can i check weither a user is existant or not.</description>
      <pubDate>Wed, 01 Feb 2006 20:36:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-in-script/m-p/3722610#M253153</guid>
      <dc:creator>Khashru</dc:creator>
      <dc:date>2006-02-01T20:36:40Z</dc:date>
    </item>
    <item>
      <title>Re: Test in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-in-script/m-p/3722611#M253154</link>
      <description>Hi :&lt;BR /&gt;&lt;BR /&gt;A simple way to test for the presence of a user in '/etc/passwd' (which works on trusted or untrusted systems) is to use 'grep' and its return status to yield a true or false answer:&lt;BR /&gt;&lt;BR /&gt;# U=jrf;grep -q "^${U}:" /etc/passwd &amp;amp;&amp;amp; echo "ok" || echo "no_user"&lt;BR /&gt;&lt;BR /&gt;The caret (^) anchors the match to the beginning of the line.  The ":" serves as the field's boundry.  A return status of zero means "ok" otherwise if no match occurs, "no_user" is printed.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 01 Feb 2006 20:53:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-in-script/m-p/3722611#M253154</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-02-01T20:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: Test in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-in-script/m-p/3722612#M253155</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;If you just want to find out if an account&lt;BR /&gt;exist in TCB database (Trusted Systems),&lt;BR /&gt;then:&lt;BR /&gt;&lt;BR /&gt;/usr/lbin/getprpw username&lt;BR /&gt;&lt;BR /&gt;It is not now clear what exactly you wish&lt;BR /&gt;to accomplish (find out if a username&lt;BR /&gt;exists, or find out a GECOS field for a&lt;BR /&gt;user :))&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;VK2COT</description>
      <pubDate>Wed, 01 Feb 2006 22:26:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-in-script/m-p/3722612#M253155</guid>
      <dc:creator>VK2COT</dc:creator>
      <dc:date>2006-02-01T22:26:29Z</dc:date>
    </item>
    <item>
      <title>Re: Test in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-in-script/m-p/3722613#M253156</link>
      <description>You can simply use as,&lt;BR /&gt;&lt;BR /&gt;echo "Enter the user name"&lt;BR /&gt;read USER&lt;BR /&gt;id ${USER} 1&amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;BR /&gt;&lt;BR /&gt;if [[ ${?} -eq 0 ]]&lt;BR /&gt;then&lt;BR /&gt;   echo "No such user please try again"&lt;BR /&gt;else&lt;BR /&gt;   echo "Enter the login name"&lt;BR /&gt;   read LNAME&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;--&lt;BR /&gt;Muthu&lt;BR /&gt;</description>
      <pubDate>Thu, 02 Feb 2006 00:31:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-in-script/m-p/3722613#M253156</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2006-02-02T00:31:19Z</dc:date>
    </item>
    <item>
      <title>Re: Test in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-in-script/m-p/3722614#M253157</link>
      <description>Hello, &lt;BR /&gt;&lt;BR /&gt;You asked about "I am using a trusted system. how can i check weither a user is existant or not." &lt;BR /&gt;&lt;BR /&gt;You can simply use, # /usr/lbin/getprpw  &lt;USERNAME&gt;&lt;BR /&gt;&lt;BR /&gt;-Arun&lt;/USERNAME&gt;</description>
      <pubDate>Thu, 02 Feb 2006 00:34:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-in-script/m-p/3722614#M253157</guid>
      <dc:creator>Arunvijai_4</dc:creator>
      <dc:date>2006-02-02T00:34:05Z</dc:date>
    </item>
  </channel>
</rss>

