码迷,mamicode.com
首页 > 其他好文 > 详细

判断用户是否存在,类型是否为管理员

时间:2016-10-08 02:58:38      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:管理员   用户名   normal   

输入一个用户名,判断该用户是admin用户或者普通用户

由于管理员用户id是1-500,而普通用户是501以上

[root@localhost ~]# vim /tmp/uidex.sh

#!/bin/bash
username=$1

if [ "$username" = "" ];then
        echo "Please input a username"
        exit 1
fi

if id $username &> /dev/null;then
        userid=$(id -u $username)
        if [ $userid -lt 500 ]; then
        echo "$username is a admin user"
        else
                echo "$username is a normal user"
        fi
else
    echo "$username is not exit"
    useradd $username
    if [ $? -eq 0 ]; then  #判断用户是否添加成功
        echo "Add user $username."
    else
        echo "Can not add $username."
    fi
fi

id $username &> /dev/null 这重定向把无用的输出消除


本文出自 “扬帆起航” 博客,请务必保留此出处http://mystery888.blog.51cto.com/9560453/1859055

判断用户是否存在,类型是否为管理员

标签:管理员   用户名   normal   

原文地址:http://mystery888.blog.51cto.com/9560453/1859055

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!