Determine whether the user's user name and group name of their base group are consistent

Source: Internet
Author: User

#!/bin/bash# pass a username parameter to the script, determine if the user's user name is consistent with the group name of their base group, and display the result # to determine if a parameter is passed if [! $#-eq 1]; Then  echo "usage:./group.sh ARG"  exit 1fi# determine if the user ID is present $ &>/dev/nullif [! $?-eq 0]; then  echo "\ n OT exits. "  Exit 1fi# takes a given user to the base group iduserid= ' ID $ | Cut-d '-f3 | cut-d=-f2 | Cut-d ' ('-f1 ' #取出组名称GROUPNAME = ' grep '. *:.*: $USERID:. * "/etc/group | cut-d:-f1 ' #判断用户名和组名是否一致if [$ = $GROUPNAME]; then< C4/>echo "UserName equals GroupName." else  echo "UserName not equals GroupName." fi############ #判断结束 ############

Optimization:

1#!/bin/Bash2 3 #传递一个用户名参数给脚本, determine whether the user name of this user is consistent with the group name of their base group and display the results4 5 #判断是否传递一个参数6 if[! $#-eq1]; Then7   Echo "usage:./group.sh ARG"8Exit19 fiTen  One #判断是否存在该用户 A#ID$1&>/dev/NULL - if!ID$1&>/dev/NULL; Then -   Echo "$ not exits." theExit1 - fi -  - #取给定用户所属基本组id +#USERID = 'ID$1|Cut-D' '-f3 |Cut-d=-f2 |Cut-D'('-F1 ' - #取出组名称 +#GROUPNAME = 'grep ". *:.*: $USERID:. *"/etc/group |Cut-D:-F1 ' A  at #判断用户名和组名是否一致 - if[ `ID-u-n $1` == `ID-g-n $1` ]; Then -   Echo "UserName equals GroupName." - Else -   Echo "UserName not equals GroupName." - fi in############ #判断结束 ############

Determine whether the user's user name and group name of their base group are consistent

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.