Shell script generation method and system and electronic equipment

By establishing a script template library and keyword library with Shell syntax structure, and using natural language instructions to generate shell scripts, the problem of testers learning the shell language is solved, and the automatic generation and cost reduction of shell scripts are achieved.

CN119415086APending Publication Date: 2025-02-11CHONGQING SELIS PHOENIX INTELLIGENT INNOVATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411469726.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-21
Publication Date
2025-02-11

AI Technical Summary

Technical Problem

In the prior art, testers with non-technical backgrounds or newcomers need to invest a lot of time and energy to learn the Shell language, resulting in a high learning curve and technical threshold for shell scripts, which increases labor and time costs.

Method used

By obtaining the keyword library and script template library, establishing script templates corresponding to the shell syntax structure, text extraction in response to natural language instructions, matching the target keywords and operation keywords, and filling in the target template to generate shell scripts.

Benefits of technology

The automatic generation of shell scripts is realized, reducing the learning curve and technical difficulty, and reducing labor and time costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119415086A_ABST
    Figure CN119415086A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of Shell scripts, and discloses a Shell script generation method and system and electronic equipment. According to the method, the script templates corresponding to the operation keywords are established through the Shell grammar structure, the script template library is formed, the target template is matched from the script template library through the target keyword extracted from the natural language instruction, and the target template is filled with the target variable extracted from the natural language instruction; a shell script corresponding to a natural language instruction is obtained, a frame of the shell script is provided through a pre-established script module, so that a target template is matched through a target keyword in the natural language instruction, then a target variable in the natural language instruction is filled into the target template to obtain the shell script, and a natural language of a user is converted into the shell script by utilizing a text extraction technology. According to the method, automatic generation of the shell script is realized, and compared with manual compiling of the shell script, the learning curve and the technical difficulty of the shell script are reduced, so that the labor cost and the time cost of the shell script are reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of Shell scripts, and in particular to a Shell script generation method, system and electronic device. Background Art

[0002] In the field of modern software development and testing, as the scale of projects continues to expand and the complexity increases, automated testing and environment management have become key links to ensure software quality and accelerate product iteration cycles. As a powerful scripting language, Shell scripts can easily integrate various testing tools with their deep system-level operation capabilities, flexible text processing functions, and wide cross-platform compatibility, and automatically execute test scripts, collect test results, and generate test reports, becoming a core component of the automated testing framework.

[0003] Although Shell scripts have many advantages in automated testing and environment management, for testers with non-technical backgrounds or new entrants, directly writing Shell scripts often faces a high learning curve and technical threshold. Testers need to invest a lot of extra time and energy to learn the Shell language, understand Shell syntax, familiarize themselves with system commands, and handle complex data structures and logical control. This requires testers to invest a lot of time and energy in learning and practicing, which increases the manpower and time costs of shell scripts. Summary of the invention

[0004] In order to provide a basic understanding of some aspects of the disclosed embodiments, a brief summary is given below. The summary is not an extensive review, nor is it intended to identify key / critical components or delineate the scope of protection of these embodiments, but rather serves as a prelude to the detailed description that follows.

[0005] In view of the above-mentioned shortcomings of the prior art, the present application provides a Shell script generation method, system and electronic device to reduce the difficulty of writing shell scripts.

[0006] The present application provides a Shell script generation method, comprising: obtaining a keyword library, wherein the keyword library is used to store operation keywords; establishing script templates corresponding to the operation keywords according to the Shell syntax structure to form a script template library; in response to a natural language instruction, obtaining a target keyword and a target variable by performing text extraction on the natural language instruction; determining a target template from the script template library according to a matching result between the target keyword and the operation keywords, and filling the target variable into the target template to obtain a shell script corresponding to the natural language instruction.

[0007] In one embodiment of the present application, natural language instructions are obtained in the following manner: a script generation program is established based on the keyword library and the script template library, wherein the script generation program is used to respond to natural language instructions, obtain target keywords and target variables by performing text extraction on the natural language instructions, determine the target template from the script template library based on the matching results between the target keywords and each of the operation keywords, and fill the target variable into the target template to obtain a shell script corresponding to the natural language instruction; in response to the script generation program being in a running state, an instruction input box is displayed to the user, and the natural language instructions input by the user are received through the instruction input box.

[0008] In one embodiment of the present application, a target keyword and a target variable are obtained by performing text extraction on the natural language instruction, including: performing text segmentation on the natural language instruction to obtain multiple text units; matching each of the text units according to the keyword library to obtain a current keyword, and determining a current variable corresponding to the current keyword from each of the text units; if the number of the current keywords is one, generating a target keyword according to the current keyword, and generating a target variable corresponding to the target keyword according to the current variable; if the number of the current keywords is multiple, classifying each of the current keywords according to a preset operation type to obtain one or more current types; if the number of the current type is one, integrating each of the current keywords to obtain a target keyword, and integrating each of the current variables to obtain a target variable corresponding to the target keyword.

[0009] In one embodiment of the present application, the method also includes: if there are multiple current types, text marking is performed on each of the text units to determine the operation objects corresponding to each of the current types according to the text marking results; by comparing between the operation objects, an object comparison result between any two current types is obtained; if the object comparison results are all different, the current keywords corresponding to the same current type are integrated to obtain the target keywords corresponding to each of the current types, and the current variables corresponding to the same current type are integrated to obtain the target variables corresponding to each of the target keywords; if any object comparison result is the same, the user is reminded that the natural language instruction is an invalid operation.

[0010] In one embodiment of the present application, the target variable is obtained in the following manner: if the natural language includes time text, the target variable corresponding to the time text is generated by calling the date() function; if the natural language includes file text, the file query script corresponding to the file text is obtained, and the target variable corresponding to the file text is returned through the file query script; if the natural language includes quantity text, the quantity text is used as the target variable.

[0011] In one embodiment of the present application, after filling the target variable into the target template and obtaining the shell script corresponding to the natural language instruction, the method also includes: obtaining the operation object corresponding to the shell script, and querying the operation permission of the shell script on the operation object; if the shell script does not have the operation permission, sending an operation permission request to the user; in response to the permission information corresponding to the operation permission request, using the Chmod tool to modify the operation permission of the shell script on the operation object.

[0012] In one embodiment of the present application, the method also includes: obtaining sample instructions; obtaining a sample script of the sample instructions by using the sample instructions as new natural language instructions; obtaining a sample execution result by executing the sample script; generating sample data based on the sample instructions, the sample script and the sample execution result, so as to optimize the keyword library and / or the script template library based on the sample data.

[0013] In one embodiment of the present application, the keyword library and / or the script template library are optimized according to the sample data in the following manner: obtaining the expected result corresponding to the sample instruction; performing similarity calculation based on the expected result and the sample execution result to obtain result similarity; if the result similarity is less than a preset similarity threshold, displaying the sample data to the user; in response to a data modification instruction corresponding to the sample data, modifying the keyword library and / or the script template library by executing the data modification instruction.

[0014] The present application provides a Shell script generation system, comprising: a keyword library for storing operation keywords; a script template library, comprising script templates corresponding to each of the operation keywords, wherein the script templates are established according to a Shell grammatical structure; a script generation program, for responding to a natural language instruction, obtaining a target keyword and a target variable by performing text extraction on the natural language instruction; determining a target template from the script template library according to a matching result between the target keyword and each of the operation keywords, and filling the target variable into the target template to obtain a shell script corresponding to the natural language instruction.

[0015] The present application provides an electronic device, comprising: a processor and a memory; the memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the electronic device executes the above method.

[0016] Beneficial effects of this application:

[0017] Through the Shell syntax structure, script templates corresponding to multiple operation keywords are established to form a script template library. The target template is matched from the script module library through the target keyword extracted from the natural language instruction, and the target template is filled with the target variable extracted from the natural language instruction to obtain the shell script corresponding to the natural language instruction. In this way, the framework of the shell script is provided by the pre-established script module, so that the target template is matched with the target keyword in the natural language instruction, and the target variable in the natural language instruction is filled into the target template to obtain the shell script. The user's natural language is converted into a shell script using text extraction technology, and the automatic generation of the shell script is realized. Compared with manually writing shell scripts, the learning curve and technical difficulty of the shell script are reduced, thereby reducing the manpower cost and time cost of the shell script. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 It is a flowchart of a Shell script generation method in an embodiment of the present application;

[0019] Figure 2 It is a flowchart of another Shell script generation method in an embodiment of the present application;

[0020] Figure 3 It is a flowchart of an optimization method of a script generation program in an embodiment of the present application;

[0021] Figure 4 It is a structural diagram of a system architecture for implementing a Shell script generation method in an embodiment of the present application;

[0022] Figure 5 It is a schematic diagram of the structure of a Shell script generation system in an embodiment of the present application;

[0023] Figure 6 It is a schematic diagram of the structure of an electronic device in an embodiment of the present invention. DETAILED DESCRIPTION

[0024] The following describes the embodiments of the present invention through specific examples, and those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the following embodiments and sub-samples in the embodiments can be combined with each other without conflict.

[0025] It should be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present invention, and thus the drawings only show components related to the present invention rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.

[0026] In the following description, numerous details are discussed to provide a more thorough explanation of the embodiments of the present invention. However, it is obvious to those skilled in the art that the embodiments of the present invention can be implemented without these specific details. In other embodiments, well-known structures and devices are shown in the form of block diagrams rather than in detail to avoid making the embodiments of the present invention difficult to understand.

[0027] The terms "first", "second", etc. in the specification and claims of the embodiments of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchanged where appropriate, so that the embodiments of the embodiments of the present disclosure described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions.

[0028] Unless otherwise stated, the term "plurality" means two or more.

[0029] In the embodiment of the present disclosure, the character " / " indicates that the preceding and following objects are in an "or" relationship. For example, A / B indicates: A or B.

[0030] The term "and / or" is a description of the association relationship between objects, indicating that three relationships can exist. For example, A and / or B means: A or B, or, A and B.

[0031] Combination Figure 1 As shown, the embodiment of the present disclosure provides a method for generating a Shell script, including:

[0032] Step S101, obtaining a keyword library;

[0033] Among them, the keyword library is used to store operation keywords;

[0034] Step S102, establishing script templates corresponding to the operation keywords respectively according to the Shell syntax structure to form a script template library;

[0035] Wherein, a shell structure grammar library is obtained to assemble shell commands according to the grammar structure in the shell structure grammar library to obtain a script template;

[0036] Step S103, in response to the natural language instruction, obtaining target keywords and target variables by performing text extraction on the natural language instruction;

[0037] Step S104, determining a target template from a script template library according to the matching result between the target keyword and each operation keyword, and filling the target variable into the target template to obtain a shell script corresponding to the natural language instruction.

[0038] The Shell script generation method provided by the embodiment of the present disclosure is adopted, and a plurality of script templates corresponding to the operation keywords are established through the Shell syntax structure to form a script template library, and the target template is matched from the script module library through the target keyword extracted from the natural language instruction, and the target template is filled in with the target variable extracted from the natural language instruction to obtain the shell script corresponding to the natural language instruction. In this way, the framework of the shell script is provided by the pre-established script module, so that the target template is matched through the target keyword in the natural language instruction, and the target variable in the natural language instruction is filled in the target template to obtain the shell script, and the user's natural language is converted into a shell script by using text extraction technology, so as to realize the automatic generation of the shell script, and compared with manually writing the shell script, the learning curve and technical difficulty of the shell script are reduced, thereby reducing the manpower cost and time cost of the shell script.

[0039] Optionally, natural language instructions are obtained in the following manner: a script generation program is established based on a keyword library and a script template library, wherein the script generation program is used to respond to natural language instructions, obtain target keywords and target variables by performing text extraction on the natural language instructions, determine the target template from the script template library based on the matching results between the target keywords and each operation keyword, and fill the target variable into the target template to obtain a shell script corresponding to the natural language instruction; in response to the script generation program being in a running state, an instruction input box is displayed to the user, and the natural language instruction input by the user is received through the instruction input box.

[0040] In some embodiments, the script generation program is developed based on the Python runtime environment; the running entry and the Python runtime environment path of the Python runtime environment are written into the .bat script, and the .bat script is executed through the user terminal, triggering the running script generation program, and an input box pops up on the user terminal; the user enters natural language instructions through the pop-up input box, for example, "query the log files generated today in the bin / log directory."

[0041] Optionally, target keywords and target variables are obtained by performing text extraction on natural language instructions, including: performing text segmentation on natural language instructions to obtain multiple text units; matching each text unit according to a keyword library to obtain a current keyword, and determining a current variable corresponding to the current keyword from each text unit; if the number of current keywords is one, generating a target keyword according to the current keyword, and generating a target variable corresponding to the target keyword according to the current variable; if the number of current keywords is multiple, classifying each current keyword according to a preset operation type to obtain one or more current types; if the number of current types is one, integrating each current keyword to obtain a target keyword, and integrating each current variable to obtain a target variable corresponding to the target keyword.

[0042] In some embodiments, text segmentation is performed using natural language libraries of Python such as NLTK (Natural Language Toolkit) and SpaCy. For example, text segmentation is performed using the function words = word_tokenize(text). The word_tokenize function is a very practical function in NLTK, which is used to split a text string into text units (Tokens). It is suitable for English text processing because the function can process punctuation marks in English, separate words and punctuation marks, and make each word or punctuation mark an independent token.

[0043] In some embodiments, the natural language instruction input by the user includes "query the log files generated today in the bin / log directory", and the script generation program extracts the target keywords as "query" and "log file"; and obtains the target template as "cat target directory\xx.log" based on the target keywords.

[0044] In some embodiments, the preset operation types include execute, export, delete, add, add, query, log, data, directory, empower, backup, create folder, modify, etc.

[0045] Optionally, the method also includes: if there are multiple current types, text marking is performed on each text unit to determine the operation object corresponding to each current type according to the text marking result; by comparing between the operation objects, the object comparison result between any two current types is obtained; if the object comparison results are all different, the current keywords corresponding to the same current type are integrated to obtain the target keywords corresponding to each current type, and the current variables corresponding to the same current type are integrated to obtain the target variables corresponding to each target keyword; if any object comparison result is the same, the user is reminded that the natural language instruction is an invalid operation.

[0046] In some embodiments, each current keyword is text-tagged by the function tags=pos_tag(words), wherein the pos_tag function is an important function in NLTK, which is used to tag the words in the text with parts of speech. Part of speech tagging is a basic task in natural language processing, which tags each word in the text with its corresponding part of speech, such as noun, verb, adjective, etc.

[0047] In some embodiments, if there are multiple current types, the operation objects are summarized and merged according to different current types. For example, the current type includes deletion. All operation objects corresponding to the current type are obtained through semantic marking, and all operation objects corresponding to the current type are integrated to obtain target parameters, so as to perform deletion operations on all operation objects through a shell command.

[0048] In some embodiments, if there are multiple operation types, it is necessary to analyze the grammatical logic to determine whether the operation objects corresponding to the operation types are the same. For example, the operation types include addition and modification, and it is necessary to determine whether the newly added object and the modified object are the same. If they are the same, the natural language instruction is an invalid operation.

[0049] Optionally, the target variable is obtained in the following manner: if the natural language includes time text, the target variable corresponding to the time text is generated by calling the date() function.

[0050] Optionally, the target variable is obtained in the following manner: if the natural language includes file text, a file query script corresponding to the file text is obtained, and the target variable corresponding to the file text is returned through the file query script.

[0051] Optionally, the target variable is obtained in the following manner: if the natural language includes quantity text, the quantity text is used as the target variable.

[0052] In some embodiments, the first 10 lines, a certain time period, and log content containing the error keyword are all target variables. There may be an intersection between the target variable and the target keyword. The target template required for the target variable is provided according to the target keyword, so as to assemble a shell script according to the target variable and the target model.

[0053] In some embodiments, the natural language instructions input by the user include "query the log files generated today in the bin / log directory"; the script generation program extracts the time text "today" from the natural language instructions, and generates today's date through the date() method; the script generation program extracts the file text from the natural language instructions, including "bin / log directory" and "log file"; a query script is generated based on the third-party library Subprocess to query the log file name in the target directory by executing the query script, and return the log file name, wherein the third-party library Subprocess is a standard library module of Python, which provides a method for generating new processes, connecting to their input / output / error pipes, and obtaining their return codes; today's log and log file name are filled into the target template to obtain a shell script.

[0054] In some embodiments, the natural language instructions input by the user include "query the first 10 lines of the target log in the target directory"; the script generation program extracts the target keywords as "query" and "first 10 lines", and then obtains the target template as "head-n num directory\xxx.log" based on the target keywords; the script generation program extracts the quantity text "first 10 lines" from the natural language instructions and fills 10 into num in the target template.

[0055] In some embodiments, if a fuzzy query is performed directly according to the natural language instructions, multiple shell instructions are obtained. For example, the shell commands corresponding to the query include cat, head, more, tail, less, find, grep, etc.; by configuring the priority of the shell instructions, the shell commands are used in sequence; however, by extracting the target keywords in the natural language instructions and querying through the target keywords, the retrieval of shell commands is more targeted. For example, when querying the first few lines of a file, it is best to query through the head command. If a fuzzy query is used, the shell command may not be matched.

[0056] In this way, by matching the target template with the target keyword in the natural language instruction, the target template is more targeted than directly performing fuzzy query based on the natural language instruction, thereby improving the execution accuracy of the shell script.

[0057] Optionally, after filling the target variable into the target template and obtaining the shell script corresponding to the natural language instruction, the method also includes: obtaining the operation object corresponding to the shell script, and querying the shell script's operation authority for the operation object; if the shell script does not have the operation authority, sending an operation authority request to the user; in response to the permission information corresponding to the operation authority request, using the Chmod tool to modify the shell script's operation authority for the operation object.

[0058] In some embodiments, if operations such as adding, deleting, and modifying are required, user permissions are required. When the user inputs a request to delete a log file in a directory, the script generation program will first obtain the operation permissions for the log file in the directory, and check whether there is deletion permission according to the group bit; if there is no deletion permission, a pop-up window will prompt the user to ask whether to authorize. If authorized, the Chmod tool will be used to modify the shell script's operation permissions for the operation object, and then the shell script of the permission directory \xxx.log will be executed. Chmod is a command line tool in Unix and Unix-like systems that is used to change the access permissions of files or directories. These permissions determine who can read, write, or execute files, and which users can enter the directory.

[0059] In some embodiments, the shell script is executed using Python's third-party library os.system() or subprocess.

[0060] In some embodiments, if the file or data needs to return a result, it is necessary to create a new file and use the push method or pull method to upload and download.

[0061] In some embodiments, before executing the shell script, the execution object of the shell script is backed up first.

[0062] Combination Figure 2 As shown, the embodiment of the present disclosure provides a method for generating a Shell script, including:

[0063] Step S201, obtaining a natural language instruction;

[0064] Step S202, obtaining a plurality of text units by performing text segmentation on the natural language instruction;

[0065] Step S203, matching each text unit according to the keyword library to obtain the current keyword, and determining the current variable corresponding to the current keyword from each text unit;

[0066] Step S204, determine whether the number of current keywords is one, if yes, jump to step S213, if no, jump to step S205;

[0067] Step S205, classifying each current keyword according to a preset operation type to obtain a current type;

[0068] Step S206, determine whether the number of the current type is one, if so, jump to step S214, if not, jump to step S207;

[0069] Step S207, marking each text unit to determine the operation object corresponding to each current type according to the text marking result;

[0070] Step S208, obtaining a comparison result between any two objects of the current type by comparing between the operation objects;

[0071] Step S209, determine whether any object comparison result is the same, if yes, jump to step S215, if no, jump to step S210;

[0072] Step S210, integrating the current keywords corresponding to the same current type to obtain target keywords corresponding to each current type, and integrating the current variables corresponding to the same current type to obtain target variables corresponding to each target keyword;

[0073] Step S211, determining a target template from a script template library according to the matching results between the target keyword and each operation keyword;

[0074] Step S212, fill the target variable into the target template to obtain a shell script corresponding to the natural language instruction.

[0075] Step S213, generating a target keyword according to the current keyword, and generating a target variable corresponding to the target keyword according to the current variable, and then jumping to step S211.

[0076] Step S214, integrating according to each current keyword to obtain a target keyword, and integrating according to each current variable to obtain a target variable corresponding to the target keyword, and then jumping to step S211.

[0077] Step S215: remind the user that the natural language instruction is an invalid operation.

[0078] The Shell script generation method provided by the embodiment of the present disclosure is adopted, and a plurality of script templates corresponding to the operation keywords are established through the Shell syntax structure to form a script template library, and the target template is matched from the script module library through the target keyword extracted from the natural language instruction, and the target template is filled in with the target variable extracted from the natural language instruction to obtain the shell script corresponding to the natural language instruction. In this way, the framework of the shell script is provided by the pre-established script module, so that the target template is matched through the target keyword in the natural language instruction, and the target variable in the natural language instruction is filled in the target template to obtain the shell script, and the user's natural language is converted into a shell script by using text extraction technology, so as to realize the automatic generation of the shell script, and compared with manually writing the shell script, the learning curve and technical difficulty of the shell script are reduced, thereby reducing the manpower cost and time cost of the shell script.

[0079] Optionally, the method also includes: obtaining sample instructions; obtaining a sample script of the sample instructions by using the sample instructions as new natural language instructions; obtaining a sample execution result by executing the sample script; generating sample data based on the sample instructions, the sample script and the sample execution result, so as to optimize the keyword library and / or the script template library based on the sample data.

[0080] In some embodiments, the sample instructions are entered manually.

[0081] In some embodiments, a long text consisting of multiple sample instructions is manually created, wherein each sentence is separated by a separator symbol; the long text is input into a preset training program, so that the long text is segmented according to the separator symbols through the training program to obtain multiple sample instructions, and the input interface of the script generation program is called in turn according to each sample instruction; sample data is generated according to the sample instructions, sample scripts and sample execution results, and saved in a preset result database for easy viewing and verification by template trainers.

[0082] In some embodiments, the keyword library and the script template library are trained for various scenarios, mainly for keyword matching and semantic analysis, to correctly understand and process the content input by the user, and to accurately produce shell scripts with corresponding logic; for example, the natural language instructions input by the user include "help me to look at a log file in the directory", and "look" is not in the keyword library, so it is necessary to train with sample instructions to increase the keyword library, or, through deep learning of the script generation program, it is determined that the user often uses target keywords such as "view" and "search" according to the frequency of previous target keywords, and then it is determined that "look" is equivalent to "view" or "search".

[0083] Optionally, the keyword library and / or script template library is optimized according to the sample data in the following manner: obtaining the expected result corresponding to the sample instruction; performing similarity calculation based on the expected result and the sample execution result to obtain the result similarity; if the result similarity is less than a preset similarity threshold, displaying the sample data to the user; and responding to the data modification instruction corresponding to the sample data, performing modifications to the keyword library and / or script template library by executing the data modification instruction.

[0084] In some embodiments, sample instructions are input into the script generation program manually or through a training program, and it is determined whether the shell script and its execution results meet the expected results. If the similarity between the expected results and the sample execution results is large, it is determined whether the problem is with the sample instructions or the script generation program. If it is a problem with the sample instructions, the keyword library is optimized; if it is a problem with the script generation program, the script template library is optimized.

[0085] Combination Figure 3 As shown, the embodiment of the present disclosure provides a method for optimizing a script generation program, including:

[0086] Step S301, obtaining a sample instruction, and obtaining an expected result corresponding to the sample instruction;

[0087] Step S302, obtaining a sample script of the sample instruction by taking the sample instruction as a new natural language instruction;

[0088] Step S303, obtaining a sample execution result by executing the sample script, and generating sample data according to the sample instruction, the sample script and the sample execution result;

[0089] Step S304, performing similarity calculation based on the expected result and the sample execution result to obtain result similarity;

[0090] Step S305, if the result similarity is less than a preset similarity threshold, the sample data is displayed to the user;

[0091] Step S306, obtaining a data modification instruction input by the user;

[0092] Step S307, modifying by executing the data modification instruction keyword library and / or the script template library.

[0093] Combination Figure 4 As shown, the present disclosure implements a system framework for implementing a Shell script generation method, including an input module, a content recognition module, a script template library, a template matching module, a script execution module, and a training module.

[0094] The input module is used to obtain natural language instructions.

[0095] The content identification module is used to obtain target keywords and target variables by performing text extraction on natural language instructions.

[0096] The script template library is used to create script templates corresponding to each operation keyword according to the Shell syntax structure.

[0097] The template matching module is used to determine the target template from the script template library according to the matching results between the target keyword and each operation keyword, and fill the target variable into the target template to obtain the shell script corresponding to the natural language instruction.

[0098] The script execution module is used to execute shell scripts.

[0099] The training module is used to obtain sample instructions; obtain sample scripts of sample instructions by taking the sample instructions as new natural language instructions; obtain sample execution results by executing the sample scripts; generate sample data based on the sample instructions, sample scripts and sample execution results to optimize the keyword library and / or script template library based on the sample data.

[0100] Combination Figure 5 As shown, the embodiment of the present disclosure provides a Shell script generation system, including a keyword library 501, a script template library 502 and a script generation program 503.

[0101] The keyword library 501 is used to store operation keywords.

[0102] The script template library 502 includes script templates corresponding to various operation keywords, wherein the script templates are established according to the Shell syntax structure.

[0103] The script generation program 503 is used to respond to natural language instructions, obtain target keywords and target variables by performing text extraction on the natural language instructions; determine the target template from the script template library based on the matching results between the target keywords and each operation keyword, and fill the target variables into the target template to obtain the shell script corresponding to the natural language instructions.

[0104] The Shell script generation system provided by the embodiment of the present disclosure is adopted, and a plurality of script templates corresponding to the operation keywords are established through the Shell syntax structure to form a script template library, and the target template is matched from the script module library through the target keyword extracted from the natural language instruction, and the target template is filled in with the target variable extracted from the natural language instruction to obtain the shell script corresponding to the natural language instruction. In this way, the framework of the shell script is provided by the pre-established script module, so that the target template is matched through the target keyword in the natural language instruction, and the target variable in the natural language instruction is filled in the target template to obtain the shell script, and the user's natural language is converted into a shell script by using text extraction technology, so as to realize the automatic generation of the shell script, and compared with manually writing the shell script, the learning curve and technical difficulty of the shell script are reduced, thereby reducing the manpower cost and time cost of the shell script.

[0105] An embodiment of the present disclosure further provides an electronic device, including: a processor and a memory; the memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the electronic device executes the above method.

[0106] Figure 6 The structure diagram of the computer system suitable for implementing the electronic device of the embodiment of the present application is shown. It should be noted that: Figure 6 The computer system 600 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0107] like Figure 6 As shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 602 or the program loaded from the storage part 608 to the random access memory (RAM) 603, such as executing the method in the above embodiment. In the RAM 603, various programs and data required for system operation are also stored. The CPU 601, ROM 602 and RAM 603 are connected to each other through a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0108] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed so that a computer program read therefrom is installed into the storage section 608 as needed.

[0109] The electronic device disclosed in this embodiment includes a processor, a memory, a transceiver and a communication interface. The memory and the communication interface are connected to the processor and the transceiver and complete communication with each other. The memory is used to store computer programs, the communication interface is used to communicate, and the processor and the transceiver are used to run the computer program so that the electronic device executes each step of the above method.

[0110] The above description and the accompanying drawings fully illustrate the embodiments of the present disclosure so that those skilled in the art can practice them. Other embodiments may include structural, logical, electrical, process and other changes. The embodiments represent possible changes only. Unless explicitly required, separate components and functions are optional, and the order of operation can be changed. Parts and sub-samples of some embodiments may be included in or replace parts and sub-samples of other embodiments. Moreover, the words used in this application are only used to describe the embodiments and are not used to limit the claims. As used in the description of the embodiments and the claims, unless the context clearly indicates, the singular forms of "a", "an" and "the" are intended to include plural forms as well. Similarly, the term "and / or" as used in this application refers to any and all possible combinations of listings containing one or more associated ones. In addition, when used in the present application, the term "comprise" and its variants "comprises" and / or comprising refer to the presence of a stated sub-sample, whole, step, operation, element, and / or component, but do not exclude the presence or addition of one or more other sub-samples, wholes, steps, operations, elements, components and / or groups of these. In the absence of further restrictions, the elements defined by the sentence "comprising a ..." do not exclude the presence of other identical elements in the process, method or device comprising the elements. In this article, each embodiment may focus on the differences from other embodiments, and the same and similar parts between the various embodiments may refer to each other. For the methods, products, etc. disclosed in the embodiments, if they correspond to the method part disclosed in the embodiments, then the relevant parts can refer to the description of the method part.

[0111] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software may depend on the specific application and design constraints of the technical solution. Technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the embodiments of the present disclosure. Technicians can clearly understand that for the convenience and simplicity of description, the specific working process of the above-described system, device and unit can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0112] In the embodiments disclosed herein, the disclosed methods and products (including but not limited to devices, equipment, etc.) can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units can be only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some sub-samples can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between each other shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms. The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to implement this embodiment. In addition, each functional unit in the embodiment of the present disclosure may be integrated in a processing unit, or each unit may exist physically alone, or two or more units may be integrated in one unit.

[0113] The flowchart and block diagram in the accompanying drawings show the possible architecture, functions and operations of the system, method and computer program product according to the embodiment of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and a part of the module, program segment or code contains one or more executable instructions for realizing the specified logical function. In some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. In the description corresponding to the flowchart and block diagram in the accompanying drawings, the operations or steps corresponding to different boxes can also occur in a different order from the order disclosed in the description, and sometimes there is no specific order between different operations or steps. For example, two consecutive operations or steps can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. Each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented by a dedicated hardware-based system that performs the specified functions or actions, or may be implemented by a combination of dedicated hardware and computer instructions.

Claims

1. A method for generating a Shell script, characterized in that: include: Acquire a keyword library, wherein the keyword library is used to store operation keywords; Establishing script templates corresponding to the operation keywords respectively according to the Shell syntax structure to form a script template library; In response to the natural language instruction, obtaining a target keyword and a target variable by performing text extraction on the natural language instruction; A target template is determined from the script template library according to the matching result between the target keyword and each of the operation keywords, and the target variable is filled into the target template to obtain a shell script corresponding to the natural language instruction.

2. The method according to claim 1, characterized in that Get natural language instructions via: A script generation program is established according to the keyword library and the script template library, wherein the script generation program is used to respond to a natural language instruction, obtain a target keyword and a target variable by performing text extraction on the natural language instruction, determine a target template from the script template library according to a matching result between the target keyword and each of the operation keywords, and fill the target variable into the target template to obtain a shell script corresponding to the natural language instruction; In response to the script generation program being in a running state, an instruction input box is displayed to the user, and a natural language instruction input by the user is received through the instruction input box.

3. The method according to claim 1, characterized in that By performing text extraction on the natural language instruction, target keywords and target variables are obtained, including: By performing text segmentation on the natural language instruction, a plurality of text units are obtained; Matching each of the text units according to the keyword library to obtain a current keyword, and determining a current variable corresponding to the current keyword from each of the text units; If the number of the current keyword is one, a target keyword is generated according to the current keyword, and a target variable corresponding to the target keyword is generated according to the current variable; If there are multiple current keywords, classify each current keyword according to a preset operation type to obtain one or more current types; If the number of the current type is one, the current keywords are integrated to obtain a target keyword, and the current variables are integrated to obtain a target variable corresponding to the target keyword.

4. The method according to claim 3, characterized in that The method further comprises: If there are multiple current types, perform text marking on each text unit to determine the operation objects corresponding to each current type according to the text marking result; By comparing the operation objects, a comparison result between any two objects of the current type is obtained; If the comparison results of the objects are all different, the current keywords corresponding to the same current type are integrated to obtain the target keywords corresponding to the current types, and the current variables corresponding to the same current type are integrated to obtain the target variables corresponding to the target keywords; If the comparison result of any object is the same, the user is reminded that the natural language instruction is an invalid operation.

5. The method according to claim 1, characterized in that Get the target variable by: If the natural language includes time text, a target variable corresponding to the time text is generated by calling the date() function; If the natural language includes a file text, obtaining a file query script corresponding to the file text, and returning a target variable corresponding to the file text through the file query script; If the natural language includes quantity text, the quantity text is used as the target variable.

6. The method according to any one of claims 1 to 5, characterized in that: After filling the target variable into the target template to obtain a shell script corresponding to the natural language instruction, the method further includes: Obtaining the operation object corresponding to the shell script, and querying the operation authority of the shell script on the operation object; If the shell script does not have the operation permission, a request for operation permission is sent to the user; In response to the permission information corresponding to the operation permission request, the Chmod tool is used to modify the operation permission of the shell script on the operation object.

7. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: Get sample instructions; Obtaining a sample script of the sample instruction by using the sample instruction as a new natural language instruction; By executing the sample script, a sample execution result is obtained; Sample data is generated according to the sample instructions, the sample scripts and the sample execution results, so as to optimize the keyword library and / or the script template library according to the sample data.

8. The method according to claim 7, characterized in that The keyword library and / or the script template library are optimized according to the sample data in the following manner: Obtaining the expected result corresponding to the sample instruction; Perform similarity calculation based on the expected result and the sample execution result to obtain result similarity; If the result similarity is less than a preset similarity threshold, displaying the sample data to the user; In response to the data modification instruction corresponding to the sample data, the keyword library and / or the script template library is modified by executing the data modification instruction.

9. A Shell script generation system, characterized in that: include: Keyword library, used to store operation keywords; A script template library, including script templates corresponding to each of the operation keywords, wherein the script templates are established according to the Shell syntax structure; A script generation program is used to respond to natural language instructions, obtain target keywords and target variables by performing text extraction on the natural language instructions; determine the target template from the script template library according to the matching results between the target keyword and each of the operation keywords, and fill the target variable into the target template to obtain a shell script corresponding to the natural language instruction.

10. An electronic device, characterized in that: include: Processor and memory; The memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the electronic device executes the method according to any one of claims 1 to 8.