标签:
一
====================================================
#!/bin/bash
#Author wenyu
#Edit date 2014 11 21
#This shell script will add a user
SYSUSER=`cat /etc/passwd | awk -F: ‘{print $1}‘`
for USERNAME in $@
do
for i in $SYSUSER
do
if [ "$i" != "$USERNAME" ];then
continue
else
echo "$i is already exist!"
break
fi
done
useradd $USERNAME 2>/dev/null
echo "$USERNAME create sucessful!"
done
#NOTICE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!....
#This shell script have logical error in "useraddd"
====================================================
二
====================================================
#!/bin/bash
#Author wenyu
#Date 2014 11 22
#Description:This script use a document "a" to judge the user if or not exist
USER_INPUT=$1
SYSUSER=`cat /etc/passwd | awk -F: ‘{print $1}‘`
for USER in $SYSUSER
do
if [ "$USER" = "$USER_INPUT" ];then
echo "hehe" > ./a
break
else
continue
fi
done
if [ -f ./a ];then
echo "$USER_INPUT is already exist!"
else
useradd $USER_INPUT
echo "$USER_INPUT create sucessful!"
fi
rm -f ./a
======================================================
三
======================================================
#!/bin/bash
# Author: Helloween
# Date: 2014/9/20
# Description: hehe
Check_user()
{
UserName=$1
AllUsers=$(cat /etc/passwd | awk -F: ‘{print $1}‘)
for i in $AllUsers
do
if [ "$i" = "$UserName" ];then
return 1
else
continue
fi
done
return 0
}
Main()
{
for i in $@
do
if `Check_user $i`;then
useradd $i
echo "$i create ok"
else
echo "$i is already exsists"
fi
done
}
Main $*;
======================================================
四
======================================================
#!/bin/bash
#Author wenyu
#Edit date 2014 11 21
#This shell script will add some user
for i in $@
do
id $i &>/dev/null
if [ $? -eq 0 ];then
echo "Sorry $i is already exist!"
else
useradd $i
echo "$i add sucessful!"
fi
done
======================================================
五
======================================================
#!/bin/bash
#Author wenyu
#Edit date 2014 11 21
#This shell script will add a user
/usr/bin/id $1 &>/dev/null
if [ $? -eq 0 ];then
echo "Sorry $1 is already exist!"
else
/usr/sbin/useradd $1
echo "The user $1 is add sucessful!"
fi
======================================================
六
=======================================================
#!/bin/bash
function user_add(){
echo "Please input which username you want to built"
read adduser
useradd $adduser &>/dev/null
if [ $? = 0 ];then
echo "Congruduation! your add user is successed "
else echo "sorry the $adduser is exit!!!"
echo -n
fi
}
user_add;
标签:
原文地址:http://www.cnblogs.com/blog-acf/p/4265681.html