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:
to test it, run this: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
hope helps.code:$ ./the_above_script.sh name_of_user_you_want_to_test
Forum The Ubuntu Forum Community Ubuntu Specialised Support Ubuntu Servers, Cloud and Juju Server Platforms [SOLVED] Checking if users exist
Ubuntu
Comments
Post a Comment