Shell Programming------Script Example

Source: Internet
Author: User
Tags md5

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.