1. Batch Add UsersCreate a TXT file for the user name and password combination userdata.txt, as follows:
123123 123 123 123 123
The script to add the above users in bulk is:
#! /bin/Bash whileRead Line Dousername=$(Echo$line |Cut-f1-d' ') #或 username=$ (Echo$line |awk '{print $s 1}') Password=$(Echo$line |Cut-f2-d' ') #或 password=$ (Echo$line |awk '{print $s 2}') Useradd $usernameif[$?-eq0]; Then Echo$password |passwd--stdin $usernameElse Echo "The user $username has been finished!" fi Done< Userdata.txt
2. File Security detectionThe mechanism of file security detection is based on the MD5 algorithm: using the MD5 algorithm to calculate the MD5 value of the file, the file is modified if it differs from the MD5 value of the original file.
#! /bin/Bashmkdir/usr/UserDatasudo chmod 777/usr/Userdatadirs="/bin/usr/bin" # commands that are not shell built-in commands are best called with full path! FIND="usr/bin/find # commands that are not shell built-in commands are best called with full path! md5sum="Usr/bin/md5sum" # commands that are not shell built-in commands are best called with full path! # Calculates the MD5 value of all files in the folder $FIND $DIRS-type F | whileRead Line Domd5sum $line>>/USR/USERDATA/MD5VALUE.MD5# > is overwrite redirect to file >> Yes append redirect to file Done# Verify that all MD5 values in the MD5VALUE.MD5 have changed (using-c) The--status parameter causes the command to produce no text output whileRead Line Do$MD 5SUM-C--status $lineif[$?-eq0]; Then Echo "$line is initial MD5" Else Echo "$line has been changed" fi Done< MD5VALUE.MD5
Shell Programming------Script Example