A script service method based on heterogeneous operating systems
By setting up an idle shell process pool and task queue in the monitored and managed host, the problems of low efficiency and excessive resource consumption in agent script execution are solved, realizing an efficient script service method that supports multiple operating systems.
Patent Information
- Application Number
- CN202210269201.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-18
- Publication Date
- 2025-12-30
- Estimated Expiration
- 2042-03-18
AI Technical Summary
In existing technologies, the Agent needs to start and stop the shell process every time it executes a script, resulting in low execution efficiency and a large number of shell processes consuming system resources, which affects the execution of normal host tasks.
Set up an idle shell process pool on the monitored and managed host, pre-start several shell processes to wait for the execution of script commands, and manage the script command tasks through a task queue and thread pool to ensure reasonable allocation and resource control of shell processes.
It improves the execution efficiency of script programs, controls system resource consumption, supports multiple operating systems, and achieves a 10-fold increase in execution efficiency while keeping resource consumption within a reasonable range.
Smart Images

Figure CN114637557B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of IT system operation and maintenance, and relates to a method for managing and executing script programs by an agent, particularly a script service-oriented method based on heterogeneous operating systems. Background Technology
[0002] During IT system operation and maintenance, Agent software is installed on each monitored and managed computer. This software communicates and interacts with the server or proxy, executes commands issued by the server, and monitors and manages the target computer. When the server issues a script execution command to the Agent, the current Agent implementation involves the Agent starting a shell process, which then executes the script command. After executing the script command, the shell process returns the result to the Agent and then exits.
[0003] The current implementation has the following problems: 1) Since starting a process is a resource-intensive and time-consuming operation, the Agent needs to start a shell process each time it executes a script, then the shell executes the script command, and finally closes the shell process. This results in low script execution efficiency and requires more time. 2) When a large number of scripts need to be executed by the Agent within a short period, the Agent starts multiple shell processes simultaneously to execute the script tasks. When too many shell processes are started, they will consume a large amount of the CPU and memory resources of the monitored and managed host, potentially causing the host's CPU and memory usage to exceed the design limits of the monitoring and management system, thereby affecting the execution of normal tasks on the host. Summary of the Invention
[0004] This invention addresses the shortcomings or deficiencies of existing technologies by providing a script service-oriented method based on heterogeneous operating systems.
[0005] The technical solution of the present invention is as follows:
[0006] A script service-oriented method based on a heterogeneous operating system is characterized by setting up an idle shell process pool in the monitored and managed host with Agent software installed. The idle shell process pool contains several shell processes that have been pre-started with the Agent software. Each pre-started shell process is an idle shell process waiting in the idle shell process pool for the Agent to retrieve it for executing script commands.
[0007] The monitored and managed host connects to the server through an Agent. The Agent has a script command task queue module. Script commands sent from the server and script commands initiated locally by the Agent first enter the script command task queue. The Agent retrieves the script command task from the head of the queue, retrieves a shell process from the idle shell process pool, and submits the script command task to the shell process for execution.
[0008] The process of submitting the script command task to the shell process for execution includes the Agent passing the script command from the shell process's standard input interface to the shell process, first entering the start command, then entering the script command, and finally entering the end command.
[0009] There are corresponding shell programs for different operating systems, which makes the script service method universal and supports various types of operating systems.
[0010] The operating system of the monitored and managed host is Windows, Linux, AIX, or HP-UX.
[0011] The number of shell processes initially started is determined by parameter configuration, and the server modifies the parameter value by issuing commands to the Agent.
[0012] The server issues commands to the Agent to modify the number of shell processes online. The Agent then starts or stops a certain number of shell processes to ensure that the number of shell processes providing script execution services is the same as the number specified by the server command. When the Agent stops shell processes, only processes that have entered the idle shell process pool are stopped to ensure that ongoing tasks are not interrupted.
[0013] Includes the following steps:
[0014] Step 1: The server downloads the script file to the Agent;
[0015] Step 2: The Agent saves the script program file locally;
[0016] Step 3: After the server passes the script commands and parameters to the Agent, the Agent puts the received script commands into the task queue. The Agent also puts locally initiated script commands, such as those scheduled for execution, into the task queue.
[0017] Step 4: The Agent sets up a dedicated thread pool to wait for tasks to arrive in the task queue. Once a task arrives, it retrieves the task and takes an idle shell process from the idle shell process pool. If there is no idle shell process, it waits.
[0018] Step 5: The Agent passes the script commands from the shell process's standard input interface to the shell process. First, enter the start command for display, then enter the script commands, and finally enter the end command for display.
[0019] Step 6: The Agent reads the output information from the shell process's standard output interface to confirm the task execution status. When it reads the message "End command displayed", it means that the script command has been executed. The Agent returns the shell process to the idle shell process pool, logs the execution result, and returns it to the script command initiator.
[0020] The technical effects of this invention are as follows: This invention provides a script service method based on a heterogeneous operating system. By setting up an idle shell process pool and placing several shell processes that start with the Agent software into the idle shell process pool as idle shell processes to wait for the execution of script commands, it can improve the efficiency of Agent executing shell script commands during IT system operation and maintenance, and control the system resources occupied by Agent when executing shell script commands.
[0021] The beneficial effects of this invention are as follows: 1. Because the shell process is pre-started, it is not necessary to start and stop the shell process every time a shell program is executed, which improves the execution efficiency of the script program. Tests have shown a 10-fold improvement in execution efficiency under certain test environments and test cases. 2. Since script commands are queued and then allocated to a fixed number of shell processes for execution, the number of shell processes executing script tasks simultaneously will not inflate due to a large number of tasks arriving at the same time, thus playing a rate-limiting role and keeping system resource usage within a reasonable range. 3. Because different operating systems have corresponding shell programs, the script service method has universality and can support various types of operating systems. Attached Figure Description
[0022] Figure 1 This is a schematic diagram of the architecture between the server and the monitored and managed host formed by implementing the script service method based on a heterogeneous operating system according to the present invention. Figure 1 The monitored host has Agent software installed, along with several shell processes that start with the Agent software to wait for script commands to be executed. The monitored host connects to the server / proxy through the Agent. The Agent has a script command task queue module. The several shell processes are all entered into an idle shell process pool as idle shell processes. The Agent executes the script command tasks retrieved from the script command task queue module by retrieving an idle shell process from the idle shell process pool.
[0023] Figure 2 This is a flowchart illustrating a script service-oriented method based on a heterogeneous operating system according to the present invention. Figure 2 The process includes the following steps: Step 1: The server downloads the script program file to the Agent; Step 2: The Agent saves the received file locally; Step 3: The server passes the script commands and parameters to the Agent, which then adds the received script commands to the task queue. The Agent also adds locally initiated script commands, such as those scheduled for execution, to the task queue; Step 4: The Agent sets up a dedicated thread pool to wait for tasks to arrive in the task queue. Once a task arrives, it retrieves the task and takes an idle shell process from the idle shell process pool. If no idle shell process is available, it waits; Step 5: The Agent passes the script commands to the shell process through the shell process's standard input interface. First, the "start display" command is entered, then the script command is entered, and finally, the "end display" command is entered; Step 6: The Agent reads the output information from the shell process's standard output interface to confirm the task execution status. When the "end display" command is read, it indicates that the script command has been executed successfully. The Agent then returns the shell process to the idle shell process pool, logs the execution result, and returns it to the script command initiator. Detailed Implementation
[0024] The following is in conjunction with the attached diagram ( Figures 1-2 The invention will be described in the following sections and examples.
[0025] Figure 1 This is a schematic diagram of the architecture between the server and the monitored and managed host formed by implementing the script service method based on a heterogeneous operating system according to the present invention. Figure 2 This is a flowchart illustrating a script service-oriented method based on a heterogeneous operating system, as described in this invention. (Reference) Figures 1 to 2 As shown, a script service-oriented method based on a heterogeneous operating system is described. An idle shell process pool is set up on the monitored and managed host with Agent software installed. This idle shell process pool contains several shell processes that have been pre-started with the Agent software. Each pre-started shell process serves as an idle shell process, waiting in the idle shell process pool for the Agent to retrieve it for script command execution. The monitored and managed host connects to the server via the Agent. The Agent has a script command task queue module. Script commands transmitted from the server and script commands initiated locally by the Agent first enter the script command task queue. The Agent retrieves the script command task from the head of the queue, retrieves a shell process from the idle shell process pool, and submits the script command task to the shell process for execution.
[0026] The process of submitting script command tasks to the shell process for execution involves the agent passing the script command from the shell process's standard input interface. First, the start command is entered, then the script command, and finally the end command. Different operating systems have corresponding shell programs, making the script service method universally applicable and supporting various operating system types. The operating system of the monitored and managed host is Windows, Linux, AIX, or HP-UX. The initial number of shell processes is determined by parameter configuration, and the server modifies the parameter value by issuing commands to the agent. The server also issues commands to the agent to modify the number of shell processes online. The agent then starts or stops a certain number of shell processes, ensuring that the number of shell processes providing script command execution services matches the number specified by the server command. When the agent stops shell processes, only processes that have entered the idle shell process pool are stopped to ensure that ongoing tasks are not interrupted.
[0027] The process includes the following steps: Step 1, the server downloads the script program file to the Agent; Step 2, the Agent saves the script program file locally; Step 3, the server transmits the script commands and parameters to the Agent, and the Agent puts the received script commands into the task queue. The Agent also puts locally initiated script commands, such as those scheduled for execution, into the task queue; Step 4, the Agent sets up a dedicated thread pool to wait for tasks to arrive in the task queue. Once a task arrives, it retrieves the task and takes an idle shell process from the idle shell process pool. If there is no idle shell process, it waits; Step 5, the Agent transmits the script commands to the shell process through the shell process's standard input interface. First, the Agent inputs the start command, then the script command, and finally the end command; Step 6, the Agent reads the output information from the shell process's standard output interface to confirm the task execution status. When the end command information is read, it indicates that the script command has been executed. The Agent returns the shell process to the idle shell process pool, logs the execution result, and returns it to the script command initiator.
[0028] This invention provides a script service-oriented method based on heterogeneous operating systems to improve the efficiency of agents executing shell script commands during IT system operation and maintenance, and to control the system resources occupied by agents when executing shell script commands. The method includes the following technical means:
[0029] When the Agent starts, it launches a number of shell processes, waiting to execute script commands. When a script command arrives, it finds an idle shell process, passes the script command to the shell process for execution, and receives the output information from the shell process executing the script command. Once a script command has finished executing, the shell process enters an idle state, waiting for the next script command to arrive.
[0030] An idle shell process pool is set up to manage idle shell processes. Once a shell process starts, it enters the idle shell process pool. When a script command needs to be executed, the agent retrieves an idle shell process from the idle shell process pool to execute the script command. After the script command is executed, the shell process enters the idle shell process pool to wait for the next script task.
[0031] When the agent executes a script command, it adds a script command to indicate the start and end of the script execution, both before and after the initial script command. The agent checks the standard output of the shell process to obtain information about whether a script command has started or finished executing.
[0032] When a script command executes a script program file, the server and agent interact twice. In the first interaction, the server downloads the script program file to the agent, which saves it locally. In the second interaction, the server downloads the script commands and parameters that call the script program file to the agent, which then immediately organizes and executes them.
[0033] The initial number of shell processes started is determined by configuration parameters, which the server can modify by issuing commands to the Agent. The server can also issue commands to the Agent to modify the number of shell processes online, allowing the Agent to start or stop a certain number of shell processes to ensure that the number of shell processes providing script execution services matches the number specified by the server command. When the Agent stops shell processes, only processes that have entered the idle shell process pool are stopped to ensure that currently executing tasks are not interrupted.
[0034] A script command task queue is set up. Script execution commands received from the server and those initiated locally by the Agent first enter the script command task queue. The Agent retrieves a script command task from the head of the queue, takes a shell process from the idle shell process pool, and submits the script command task to the shell process for execution. If there are no script command tasks or no idle shell processes, it waits.
[0035] For different operating systems, launch the corresponding shell program. For example, launch cmd for Windows, sh for Linux, and the appropriate shell program for AIX, HP-UX, and other operating systems. Some operating systems have multiple shell programs. To reduce the workload of system administrators, it is recommended to launch the same shell program for the same operating system.
[0036] like Figure 1 As shown, Agent software is installed on each monitored computer to communicate and interact with the server or proxy, execute commands issued by the server, and monitor and manage the target computer. When the Agent starts, it also starts a certain number of shell processes. These processes enter an idle shell process pool, waiting to execute script commands. The initial number of shell processes is determined by parameter configuration, and the server can modify the parameter value by issuing commands to the Agent. The server can also issue commands to the Agent to modify the number of shell processes online, allowing the Agent to start or stop a certain number of shell processes, ensuring that the number of shell processes providing script command execution services is the same as the number specified by the server command. When the Agent stops shell processes, only processes that have entered the idle shell process pool are stopped to ensure that ongoing tasks are not interrupted. For different operating systems, the corresponding shell program is launched. For example, for Windows, the cmd program is launched; for Linux, the sh program is launched; and for AIX, HP-UX, and other operating systems, the corresponding shell program is launched. Some operating systems have multiple shell programs; to reduce the workload of maintenance, it is recommended to launch the same shell program for the same operating system.
[0037] A script command task queue is set up. Script execution commands received from the server and those initiated locally by the Agent first enter the script command task queue. The Agent retrieves a script command task from the head of the queue, takes a shell process from the idle shell process pool, and submits the script command task to the shell process for execution. If there are no script command tasks or no idle shell processes, it waits.
[0038] The script command execution flow is as follows: Figure 2 As shown. Script commands can be either executing a script program file or other shell commands. When the script command is to execute a script program file, this script program file needs to be passed to the Agent by the server.
[0039] Figure 2 This describes the situation when a script command executes a script program file.
[0040] The server downloads the script file to the Agent.
[0041] After receiving the file, the agent saves it locally.
[0042] The script command task queue stores tasks from two sources: script execution commands passed from the server and script execution commands initiated locally by the Agent.
[0043] The script execution command received from the server is passed from the server to the Agent along with the script command and parameters, and then placed into the task queue by the Agent.
[0044] The Agent initiates script execution commands locally, and then puts scheduled script command tasks into the task queue.
[0045] The agent sets up a thread pool, with the number of threads in the pool being equal to the number of shell processes. Threads read script commands from the task queue and execute them.
[0046] After reading the tasks in the task queue, the thread retrieves an idle shell process from the idle shell process pool. If there is no idle shell process, it waits until an idle shell process is retrieved.
[0047] The standard I / O operations of a shell process include standard input (stdin), standard output (stdout), and standard error (stderr), which correspond to three streams in Java: getOutputStream(), getInputStream(), and getErrorStream().
[0048] For each task in the task queue, the Agent adds a start command and an end command before and after it, respectively. These script commands are then passed to the shell process through the shell process's standard input interface.
[0049] The Agent reads output information from the standard output interface of the shell process to confirm the task execution status. When it reads the message indicating the end of the command, it means that the script command has been executed. The Agent then returns the shell process to the idle shell process pool, logs the execution result, and returns it to the transaction initiator.
[0050] Contents not described in detail in this specification are prior art known to those skilled in the art. It is hereby indicated that the above description is intended to help those skilled in the art understand this invention, but does not limit the scope of protection of this invention. Any equivalent substitutions, modifications, improvements, and / or simplifications of the above descriptions that do not depart from the essential content of this invention fall within the scope of protection of this invention.
Claims
1. A script service method based on heterogeneous operating systems, characterized by, In the monitored management host installed with the Agent software, an idle shell process pool is set, which contains a plurality of shell processes started in advance with the start of the Agent software, each of the pre-started shell processes being an idle shell process in the idle shell process pool waiting to be taken out by the Agent to execute a script command; The server modifies the number of shell processes on-line by issuing a command to the Agent, and the Agent starts or stops a certain number of shell processes, so that the number of shell processes providing the script command execution service is the same as the number specified by the server command, and when the Agent stops a shell process, only the process entering the idle shell process pool is stopped to ensure that the execution of the task is not interrupted; The monitored management host connects to the server through the Agent, and a script command task queue module is set in the Agent, and the script commands transmitted from the server and the script commands initiated locally by the Agent are all queued in the script command task queue first, the Agent takes out the script command task from the head of the queue, takes out a shell process from the idle shell process pool, and submits the script command task to the shell process for execution; The method comprises the following steps: Step 1: the server downloads a script program file to the Agent; Step 2: the Agent saves the script program file locally; Step 3: the server transmits a script command and parameters to the Agent, and the Agent puts the received script command into a task queue, and the Agent puts a script command initiated locally, such as a timing execution, into the task queue; Step 4: the Agent sets a special thread pool to wait for a task from the task queue, and once a task arrives, the Agent takes out the task and takes out an idle shell process from the idle shell process pool, and waits if there is no idle shell process; Step 5: the Agent transmits the script command from a shell process standard input interface to the shell process, inputs a display start command first, then inputs the script command, and finally inputs a display end command; Step 6: the Agent reads output information from a shell process standard output interface, confirms the execution state of the task, and when the information of the display end command is read, it is indicated that the script command has been executed, the shell process is returned to the idle shell process pool, the execution result is logged, and the script command initiator is returned.
2. The heterogeneous operating system based script service method of claim 1, wherein, The submission of the script command task to the shell process for execution comprises that the Agent transmits the script command from a shell process standard input interface to the shell process, inputs a display start command first, then inputs the script command, and finally inputs a display end command.
3. The heterogeneous operating system based script service method of claim 1, wherein, There are corresponding shell programs for different operating systems, so that the script service method is universal to support various types of operating systems.
4. The heterogeneous operating system based script service method of claim 1, wherein, The operating system of the monitored management host is windows or linux or AIX or HP-UX.
5. The heterogeneous operating system based script service method of claim 1, wherein, The number of shell processes initially started is determined by the configuration of the parameters, and the server modifies the values of the parameters by issuing commands to the Agent.
Citation Information
Patent Citations
An application server calling method and system based on Nginx
CN109788008A
Method and system for monitoring terminal equipment based on script server
CN112711511A