adduser.sh
来自「Solaris环境下Shell编程编程」· Shell 代码 · 共 93 行
SH
93 行
#!/bin/sh# Purpose: To write a script to add user to the system.# Name: adduser.sh# Check for only a single command line argumentif [ $# -ne 1 ]then echo "Usage: adduser newusername" exit 1fi# Assign the value of $1 to the variable namename=$1if grep "^$name:" ./mypasswd > /dev/null 2>&1then echo "The username $1 is already in use, here " echo "is the entry from the ,/mypasswd file." echo grep "^$name:" ./mypasswd exit 2fi# Use nawk to extract all the UIDs into the temp file currentuidnawk -F: '{print $3}' ./mypasswd > ./currentuid# Use sed to remove all 1, 2, and 3 digit UIDs from currentuid, and# place the output in the temp file currentuid2sed -e '/^.$/d' -e '/^..$/d' -e '/^...$/d' ./currentuid > ./currentuid2# Use sed to remove UIDs 60001, 60002, and 65534 from currentuid2,# and place the output in the temp file currentuid3sed -e '/^6000[12]$/d' -e '/^65534$/d' ./currentuid2 > ./currentuid3# Sort the UIDs in currentuid3 numericallysort -n ./currentuid3 > ./currentuid4# Calculate the next available UIDlastuid=`sed -n '$p' ./currentuid4`uid=`expr $lastuid + 1`echo "The uid for $name is: $uid"# Prompt for a group name and verify whether it exists in /etc/groupecho "What primary group should $a belong to? "echo "Please specify the group name: \c"read group junkgrep "^$group:" /etc/group > /dev/null 2>&1if [ $? -ne 0 ]then echo "The group $group is not valid." echo exit 2fiecho "Good, now select a login shell for user $1"cat << LOGINSHELLS> csh> ksh> shLOGINSHELLSread ushellif [ $ushell = "csh" -o $ushell = "ksh" -o $ushell = "sh" ] then echo "Please enter the comment information for the user:" read comment echo "The new user entry looks like this:" echo "$1:x:$uid:$group:$comment:/export/home/$1:$ushell" echo " " echo "New user $1 has been added to the ./mypasswd file" echo "$1:x:$uid:$group:$comment:/export/home/$1:$ushell" >> ./mypasswdelse echo "Sorry, that is not a valid shell, exiting..." exit 3fi
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?