⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adduser.ksh

📁 Solaris环境下Shell编程编程
💻 KSH
字号:
#!/bin/ksh# Purpose: To write a script to add user to the system. Generate a#          menu for the login shell choices.## Name: adduser.ksh# 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 2fiPS3="Enter the number: "select ushell in csh ksh shdo	case $ushell in	csh)    		print "$ushell was selected."   		break 		;;	ksh)    		print "$ushell was selected."   		break 		;;	sh)     		print "$ushell was selected."  		break 		;;	*)      		print "Unknown choice, try again." 		;;	esacdoneif [ $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..."fi      

⌨️ 快捷键说明

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