Skip to content

Instantly share code, notes, and snippets.

@jieniu
Created January 22, 2017 05:52
Show Gist options
  • Save jieniu/14da2c3ca7a4d9abe774d0c07a11477d to your computer and use it in GitHub Desktop.
Save jieniu/14da2c3ca7a4d9abe774d0c07a11477d to your computer and use it in GitHub Desktop.
useradd.sh
#!/bin/sh
SALT_HOME="/srv/salt/user"
if [ $# -lt 3 ]
then
echo "usage: $0 username passwd hostnames group"
echo "example: sudo ./useradd.sh test test ko-79,ko-78 dev"
exit
fi
username=$1
passwd=$2
host=$3
group=$4
groupLen=${#group}
password=`openssl passwd -1 -salt $username $passwd`
echo "${username}:" > ${SALT_HOME}/useradd.sls
echo " user.present:" >> ${SALT_HOME}/useradd.sls
echo " - fullname: ${username}" >> ${SALT_HOME}/useradd.sls
echo " - password: ${password}" >> ${SALT_HOME}/useradd.sls
if [ $groupLen -gt 0 ]
then
echo " - groups:">> ${SALT_HOME}/useradd.sls
echo " - $group">> ${SALT_HOME}/useradd.sls
fi
echo "salt -L \"$host\" state.sls user.useradd"
salt -L "$host" state.sls user.useradd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment