Functional requirements: 1. create a new user. generally, create a sub-directory named "/home". 2. add a new user record to the/etc/passwd file. 3. add new user records to the/etc/shadow file. Code implementation: the while, chown, chgrp, and other statements are used. #! /Bin...
Functional requirements: 1. create a new user, which is usually a subdirectory named by user name in/home.
2. add new user records in the/etc/passwd file.
3. add new user records to the/etc/shadow file.
Code implementation:
Use the while, chown, chgrp, and other statements.
#! /Bin/bash // define the script execution environment
# Filename: create a file // define a file name
I = 1 // define the variable
Awk 'In in {FS = ":" ;}{ print $3 ;} '/etc/passwd> pa // indicates to save the bottom three columns of the passwd file with the colon separator to the pa file, "BEGIN" indicates processing starts from the first character of each line in the/etc/passwd file. the code in this line extracts the third line from the file/etc/passwd and saves it to the file pa.
X = 'tail-200' // save the first line of the file pa to variable x, that is, variable x stores the largest user ID currently. here, "· tail-l Pa'" is quoted in reverse quotation marks.
X = $ ($ x + 1) // add the x value of the variable to 1 as the id of the next group of new users.
While [$ I-le 50] // The loop structure is less than 50 and more than 50 ends the loop body.
The structure in the do // loop statement.
Mkdir-p/home/stud $ {I} // use the mkdir command to create the user's home directory,
Chown-R $ stud $ {I}/home/$ stud $ {I} // use chown to specify the main directory,
Chgrp-R user1/home/$ stud $ {I} // use chgrp to specify the main directory
Echo "stud $ {I}: x :$ {x}: 100:/home/stud $ {I }: /bin/bash ">/etc/passwd // Append the string to the end of/etc/passwd
Echo "stud $ {I }:: 14098: 0: 9999: 7: ::::" >>/ etc/shadow // Append the string to the end of the file
I = $ ($ I + 1) // add 1 to the variable
X = $ ($ x + 1) // add the variable x value to 1
Done // indicates the end of the loop body
This article is from the "Happy first" blog