shell脚本添加账号并指定密码

#!/bin/bash
#by kevin
#2019-01-21

name=kevin
pass=kevin@123
echo "you are setting username : ${name}"
echo "you are setting password : $pass for ${name}"

useradd $name
if [ $? -eq 0 ];then
   echo "user ${name} is created successfully!!!"
else
   echo "user ${name} is created failly!!!"
   exit 1
fi

echo $pass | passwd $name --stdin  &>/dev/null
if [ $? -eq 0 ];then
   echo "${name}'s password is set successfully"
else
   echo "${name}'s password is set failly!!!"
fi

--------------------------------------------------------------------

备注:

1、name=kevin,是指定用户名;

2、pass=kevin@123,是指定密码。

 

你可能感兴趣的:(shell)