Skip to content

Instantly share code, notes, and snippets.

@seocam
Created August 6, 2014 01:06
Show Gist options
  • Save seocam/4f25253d8951c3583cdd to your computer and use it in GitHub Desktop.
Save seocam/4f25253d8951c3583cdd to your computer and use it in GitHub Desktop.
Scripts para criar/modificar usuários
#! /bin/sh
USER=$1; GROUP=$2; HOME=$3
if [ 0 -ne $(getent passwd $USER > /dev/null)$? ]
then useradd $USER --home $HOME --gid $GROUP -n; fi
OLDGID=`getent passwd $USER | awk -F: '{print $4}'`
OLDGROUP=`getent group $OLDGID | awk -F: '{print $1}'`
OLDHOME=`getent passwd $USER | awk -F: '{print $6}'`
if [ "$GROUP" != "$OLDGID" ] && [ "$GROUP" != "$OLDGROUP" ]
then usermod --gid $GROUP $USER; fi
if [ "$HOME" != "$OLDHOME" ]
then usermod --home $HOME $USER; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment