Skip to main content

Thread: Checking if users exist


hi guys.
not sure if right place fo but....

i'm learning write bash scripts. i'm experimenting on ubuntu server 11.04 virtual machine.

part of script want automate user creation.

there way check if user exists in script. can like

code:
if userexists;   else  instead  fi

there's no simple command (at least know). have search /etc/passwd file. part of working code have used in past:
code:
#!/bin/bash    userexist()  {     awk -f":" '{ print $1 }' /etc/passwd | grep -x $1 > /dev/null     return $?  }      userexist $1  if [ $? = 0 ];     echo "$1 exists."  else     echo "$1 not exist."  fi
to test it, run this:
code:
$ ./the_above_script.sh   name_of_user_you_want_to_test
hope helps.


Forum The Ubuntu Forum Community Ubuntu Specialised Support Ubuntu Servers, Cloud and Juju Server Platforms [SOLVED] Checking if users exist


Ubuntu

Comments

Popular posts from this blog

How to change text Component easybook reloaded *newbee* - Joomla! Forum - community, help and support

After Effect warning: A problem occurred when processing OpenGL commands

Preconditions Failed. - Joomla! Forum - community, help and support