finger command

Hello all,

Here is what I am trying to do. If a user exist, then send an echo "EXIST" or else "DOES NOT EXIST". (under HP-UX)

Kind of:

#!/usr/bin/sh
USER=mylogin

finger $USER

if $? = 0
then
     echo "EXIST""
else
     echo "DOES NOT EXIST"
fi

Does not work at all. Any idea?

I have no access to HP-UX and finger is not present in my system.
But I would try "who" piped to "grep" for this purpose.

It should be

if [ $? -eq 0 ];

Checked on HP-UX system

......................................
#!/usr/bin/sh
USER=mylogin

finger $USER > /dev/null ### Will not display the output of finger command

if [ $? -eq 0 ]
then
echo "EXIST""
else
echo "DOES NOT EXIST"
fi
........................................

Finger is disabled on all our servers, just like talk, and rwall are.

You would be better of getting the info from the passwd file.

finger wont help as when I gave bogus username it still gave and o/p for $? as 0

Cheers,

Try:

cat /etc/passwd | grep username 1>/dev/null 2>&1

if [ $? != 0 ]
then
echo user does not exist
else
echo user does exist
fi

a far better way, becasue it works irrespective of the where the passwd entries are stored would be:

getent passwd username > /dev/null 2>&1
if [[ $? -eq 0 ]] ; then
   echo user exists
else
   echo user soes not exists
fi

What is getent???

can you explain the same.

cheers

Doesn't HP have the id command?

This works in HP-UX:

if id username >/dev/null 2>&1; then
  echo "username exists"
else
  echo "username doesn't exist"
fi

Or as a one-liner:

id username >/dev/null 2>&1 && echo "exists" || echo "doesn't exist"