In linux/centos shell scripts, the password is not interactively modified. In centos, the password is not modified.

Source: Internet
Author: User

In linux/centos shell scripts, the password is not interactively modified. In centos, the password is not modified.
Today, when I wrote a shell script, I found that the user's password needs to be set and the password is set to interactive. This is obviously not good in the script, So I went online to search for information, two non-interactive password setting methods are found:

1. Use chpasswd
In fact, chpasswd uses the user to enter the 'user name: password' to change the passwords of a group of users. It is also a tool for changing passwords in batches. For details about the usage, see chpasswd usage.
Format: # echo Username: Password | chpasswd

For example, to add a doiido account with a password of 123456, run the following command:
# Echo doiido: 123456 | chpasswd


2. Use passwd and -- stdin combination
Passwd uses the terminal as the standard input by default, and -- stdin indicates that any file can be used as the standard input. The two combinations can directly change the password.
Format: # echo 'Password' | passwd -- stdin User Name

Add a doiido account with a password of 123456. The command is as follows:
# Echo '000000' | passwd -- stdin doiido


In this way, the password can be changed in non-interactive mode, but export can be used for some embedded linux methods.



Which of the following statements about the sed command in linux knows what the sed command is? Sed's/\/g'

Truncates or modifies a string and prints it to the screen.
Usage: sed parameter 'action' action object
If you use the-I parameter to modify the document content, I will give you a similar analysis of your sed's/\/g.
Sed's/old/new/G '***
This is to replace the word "old" in the *** document with the word "new.
In your sed's/\/g ', both convert/\\/. S/\ // is a part of it. The word to be replaced is similar to the old one, therefore, use \ to convert it into a common symbol/, and use \/g to replace the old new from the first symbol to the new symbol before g, for \/, the first two \ is \ has no special meaning, so it is \. For the second one before g, \ is used for conversion because of its special meaning, so new is \\/. The/in s/old/new/g is required in a fixed format, so if you want to print out/, use \ for conversion, and use \ for conversion of linux special characters \.
The detailed parameter information is man page, which is indispensable, because one person cannot remember all those things. If you remember it, it is better to remember three hundred Tang poems. As long as you know how this command or tool works, you can use it in a clear way. You can check it when you need it. There is no need to go with yourself.

How to Use the sed command in linux? Detailed description

Sed editor is one of the most useful assets in the Linux System Administrator toolkit.

One of the biggest advantages of Linux is that it comes with a variety of practical tools. There are so many different utility tools that it is almost impossible to know and understand all of them. A utility that simplifies operations in critical cases is sed. It is one of the most powerful tools in any administrator's toolkit and can prove itself valuable in critical situations.

Sed utility is an "Editor", but it is different from most other editors. In addition to not facing the screen, it is still non-interactive. This means that you must insert the command to be executed on the data to the command line or the script to be processed. When it is displayed, forget the interactive file editing feature that you have when using Microsoft Word or most other editors. Sed is non-interactive in a file (or file set) and receives and executes a series of commands without asking. As a result, it flows through the text just like a stream passing through a stream, so sed properly represents a stream editor. It can be used to change all "Mr. Smyth" that appear to "Mr. Smith" or "tiger cub" to "wolf cub ". The stream editor is very suitable for executing repeated edits, which takes a lot of time if manually completed. Its parameters may be as limited as the parameters required to use a simple operation at a time, or as complex as a script file with thousands of lines to edit and modify. Sed is one of the most useful tools in Linux and UNIX toolbox, and has very few parameters.

How sed works

Sed utility reads files into the memory sequentially. It then executes all the operations specified for the row and puts the row back to the memory after the request is modified to dump it to the terminal. After all the operations on this row are completed, it reads the next row of the file and repeats the process until it completes the file. As mentioned above, the default output is to output the content of each row to the screen. Here, two important factors are involved: first, the output can be redirected to another file to save the changes; second, the source file (by default) remains unchanged. Sed reads the entire file by default and modifies each row. However, you can restrict the operation to the specified row as needed.

The syntax of this utility is:

Sed [options] '{command}' [filename]

In this article, we will explore the most common commands and options and demonstrate how they work and where they are suitable for use.

Replacement command

One of the most common commands of sed utility and any other similar editor is to replace another value with one value. The command syntax used to perform this operation is as follows:

'S/{old value}/{new value }/'

Therefore, the following demonstrates how to easily change "tiger" to "wolf ":

$ Echo The tiger cubs will meet on Tuesday after school | sed
'S/tiger/wolf /'
The wolf cubs will meet on Tuesday after school
$

Note that if the input is from the previous command output, you do not need to specify the file name-the same principle applies to awk, sort, and most other LinuxUNIX command line utilities.

Multiple modifications

If you need to modify the same file or row multiple times, you can implement it in three ways. The first option is to use the "-e" option, which notifies the program that multiple editing commands are used. For example:

$ Echo T... the remaining full text>
 

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.