adduser.ksh

来自「Solaris环境下Shell编程编程」· KSH 代码 · 共 53 行

KSH
53
字号
#!/bin/ksh# Purpose: To write a script to add user to the system.# Name: adduser,ksh# Check for only a single command line argumentif [[ $# != 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	print "The username $1 is already in use, here "	print "is the entry from the ,/mypasswd file."	print	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 = lastuid + 1 ))echo "The uid for $name is: $uid"

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?