Wednesday, June 05, 2013

 

[linux] script para saber si un usuario y un grupo existen o no

#!/bin/bash

# check the group 
res=$(grep -c "$1:" /etc/group);
if [ $res -eq 1 ]; then
  echo ".. group $1 exists"
else
  echo ".. group $1 does not exist, create it "
  groupadd $1
  # groupdel $1 (to remove the group)
fi

# the check the user
if id -u $1 >/dev/null 2>&1; then
  echo ".. user $1 exists"
else
  echo ".. user $1 does not exist, create it and add him to groups video and $1"
  useradd -G $1,video -d /home/$1 -m -s /bin/bash $1
  # userdel $1 (to remove the user)
fi

Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?