Multi-layered hop session management method, device and equipment based on multi-naming session and medium

By maintaining multiple named sessions and detecting prompts in real time during operation and maintenance management, the problem of command failure in multi-level access across bastion hosts is solved, and high reliability and high success rate of multi-level jump command execution are achieved.

CN123055773APending Publication Date: 2026-11-06SHENZHEN YINXING INTELLIGENT DATA CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611485866.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-23
Publication Date
2026-11-06

AI Technical Summary

Technical Problem

In operation and maintenance management scenarios, when multiple levels of access are performed across bastion hosts, the traditional command nesting method causes quotation marks and special characters to be swallowed or escaped incorrectly, making it impossible to maintain directory and user states, resulting in command failure and difficulty in troubleshooting. Furthermore, it is impossible to achieve effective parallel management and location when operating on multiple machines.

Method used

By maintaining multiple named sessions, each session independently records the current directory, user, and jump link status. The real-time interactive channel sends commands and detects the completion of command execution based on the prompt. The status is updated during each jump, and the prompt is matched using editing similarity to adapt to environmental changes.

Benefits of technology

It solves the problem of directory and user state not being maintained in the traditional nested command method, improves the reliability and success rate of command execution in multi-level jump scenarios, and avoids the phenomenon of quotation marks and special characters being swallowed or escaped incorrectly layer by layer.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123055773A_ABST
    Figure CN123055773A_ABST
Patent Text Reader

Abstract

This application relates to a method, apparatus, device, and storage medium for multi-level jump session management based on multiple named sessions. The method includes: maintaining multiple named sessions, each including a real-time interaction channel with a remote device based on a remote terminal protocol; obtaining the command text to be executed; when the command text does not specify a target session identifier, sending the command text to the current default named session, and then sending the command text to the corresponding remote shell for execution through the real-time interaction channel corresponding to the current default named session; when the command text specifies a target session identifier, sending the command text to the specified named session, and then sending the command text to the corresponding remote shell for execution through the real-time interaction channel corresponding to the specified named session. This application avoids the phenomenon of quotation marks and special characters being swallowed or escaped incorrectly layer by layer during the parsing of multi-level shell nesting, improving the reliability and success rate of command execution in complex jump scenarios.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of network communication technology, and in particular to a method, apparatus, device and storage medium for multi-level jump session management based on multi-named sessions. Background Technology

[0002] In operation and maintenance management scenarios, when performing multi-level access across bastion hosts, the traditional approach requires nesting multiple layers of SSH calls within a single command. The more nested the layers, the more likely quotation marks, pipes, and special characters are to be swallowed or misescaped during the layer-by-layer shell parsing process, leading to command failures and difficulties in troubleshooting. Simultaneously, existing stateless sessions cannot maintain directory, user, and jump connection states, requiring repeated reconnections for multi-step operations. When multiple machines need to be operated simultaneously, multiple unrelated terminals must be opened, and the host, user, and directory states of each terminal must be manually remembered, making effective parallel management and location impossible. Summary of the Invention

[0003] In view of the above, this application provides a multi-level jump session management method, apparatus, device and storage medium based on multi-named sessions, the purpose of which is to solve the above-mentioned technical problems.

[0004] Firstly, this application provides a multi-level jump session management method based on multiple named sessions, the method comprising: Maintain multiple naming sessions, each of which includes a real-time interaction channel with a remote device based on a remote terminal protocol, and each of which independently records the current directory, the current user identifier, and the status of the established jump links; Get the text of the command to be executed; When the command text does not specify a target session identifier, the command text is sent to the current default named session, and then sent to the corresponding remote shell for execution through the real-time interaction channel corresponding to the current default named session; When the command text specifies a target session identifier, the command text is sent to the specified named session, and then, through the real-time interaction channel corresponding to the specified named session, the command text is sent to the corresponding remote shell for execution; and The current prompt of the named session executing the command text is parsed, the current host information and current user information are extracted from the current prompt, and the named session executing the command text is determined as the new default named session.

[0005] In some embodiments, sending the command text to the corresponding remote shell for execution via the real-time interaction channel corresponding to the current default naming session or the specified naming session includes: When the execution path corresponding to the command text needs to jump across multiple network devices, the user switch command and / or remote login jump command are sent sequentially to the current Shell through the real-time interaction channel. After each switching command is sent, the raw output stream returned by the switching command is received through the real-time interactive channel; The system detects whether the switching command has been completed based on the prompt in the original output stream, and sends the next switching command only after confirming that the command has been completed, until all the jumps from the current level to the target level are completed. During the hierarchical hop process, after each hop is completed, the current directory, current user ID, and hop link status in the current named session record are updated to the hopped status, so that subsequent commands can be executed directly using the updated status.

[0006] In some embodiments, detecting whether the switching command has been completed based on the prompt in the original output stream includes: Retrieve the preset prompt regular expression template; Match the last character of the original output stream with the prompt regular expression template; If a match is found, the switching command is considered to have been executed successfully. If the match fails, the original output stream is reversed and the candidate string after the last newline character is extracted. The ANSI control characters in the candidate string are removed and used as the candidate prompt. Based on the edit similarity between the candidate prompt and the template that was most recently successfully matched in the naming session history, it is determined whether the toggle command has been executed.

[0007] In some embodiments, determining whether the toggle command has been completed based on the edit similarity between the candidate prompt and the most recently successfully matched template in the naming session history includes: Calculate the number of character editing operations between the candidate prompt and the most recently successfully matched template, the editing operations including character insertion, deletion and replacement; The normalized edit distance is obtained by dividing the number of edit operations by the maximum length of the candidate prompt and the most recently successfully matched template, and the edit similarity is determined based on the normalized edit distance. When the edit similarity is higher than a preset threshold, the most recently successfully matched template is taken as the detection result and the switching command is determined to have been executed.

[0008] In some embodiments, after taking the most recently successfully matched template as the detection result and determining that the switching command has been executed, the method further includes: The candidate prompts are stored as supplementary templates in the temporary cache of the corresponding naming session, and a lifecycle timer is created for the supplementary templates and a valid expiration time is set. Before the lifecycle timer expires, when the naming session triggers the completion detection of the switching command again, the tail character of the received original output stream is matched with the supplementary template in the temporary buffer based on edit similarity. If a match is successful, determine whether the current time has exceeded the valid deadline. If the current time has not exceeded the effective deadline, then refresh the lifecycle timer and reset the consecutive failure count of the supplementary template to zero; If the current time has exceeded the effective deadline, the supplementary template is discarded and removed from the temporary cache. If a match fails, the consecutive failure count of the supplementary template is incremented by 1. If the consecutive failure count of the supplementary template exceeds the failure count threshold, the supplementary template is removed from the temporary cache. After removal, if a match is successful again, it is stored back in the cache with the initial lifespan.

[0009] In some embodiments, the method further includes, before sending the command text to the current default naming session: Obtain the activity status of the real-time interactive channel corresponding to the current default named session; When it is detected that the current default naming session is actively closed or the network connection is interrupted, it is confirmed that the current default naming session is invalid. According to the preset list of live session priorities, select the highest priority naming session from the remaining naming sessions other than the current default naming session as the new default naming session; The identifier of the new default naming session is reported, and the invalid default naming session is removed from the list of live sessions or set to an unselectable state.

[0010] In some embodiments, when command texts to be executed are simultaneously obtained from multiple clients, the method further includes: Configure an independent command execution lock and a command request queue associated with the command execution lock for each named session; When the same naming session receives multiple command texts to be executed from different clients, the multiple commands are stored in the command request queue of the naming session in the order of receipt time, and each command request is assigned an incrementing sequence number. Acquire the command execution lock before retrieving the head command from the command request queue by the execution thread; If the command execution lock is already held by another execution thread, the current execution thread enters a blocked waiting state until the command execution lock is released; After successfully acquiring the command execution lock, the command text with the smallest sequence number is retrieved from the command request queue and sent to the corresponding remote shell for execution through the real-time interaction channel of the named session.

[0011] Secondly, this application provides a multi-level jump session management device based on multiple named sessions, the multi-level jump session management device based on multiple named sessions includes: The maintenance module is used to maintain multiple naming sessions. Each naming session includes a real-time interaction channel with a remote device based on a remote terminal protocol, and each naming session independently records the current directory, the current user identifier, and the status of the established jump links. The acquisition module is used to acquire the text of the command to be executed; The first sending module is used to send the command text to the current default named session when the command text does not specify a target session identifier, and send the command text to the corresponding remote shell for execution through the real-time interaction channel corresponding to the current default named session; The second sending module is configured to send the command text to a specified named session when the command text specifies a target session identifier, and to send the command text to the corresponding remote shell for execution via the real-time interaction channel corresponding to the specified named session; and The parsing module is used to parse the current prompt of the named session executing the command text, extract the current host information and current user information from the current prompt, and determine the named session executing the command text as the new default named session.

[0012] Thirdly, this application provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; When a processor executes a program stored in memory, it implements the steps of the multi-level jump session management method based on multiple named sessions as described in any embodiment of the first aspect.

[0013] Fourthly, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps of the multi-level jump session management method based on multiple named sessions as described in any embodiment of the first aspect.

[0014] The technical solutions provided in this application have the following advantages compared with the prior art: By independently maintaining a real-time interaction channel, current directory, user identifier, and jump link status for each named session, the state of each level in a multi-level jump process can be persistently maintained. Subsequent commands can reuse the existing jump context without repeating the switching operation, solving the problems of repeated authentication and repeated connection caused by the inability to maintain directory and user states in traditional nested command methods. Since the command text is executed directly to the current remote shell through the established interaction channel, the phenomenon of quotation marks and special characters being swallowed or escaped incorrectly during the parsing of multi-level nested shells is completely avoided, significantly improving the reliability and success rate of command execution in complex jump scenarios. Attached Figure Description

[0015] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0016] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0017] Figure 1 This is a flowchart illustrating a preferred embodiment of the multi-level jump session management method based on multi-named sessions in this application; Figure 2 This is an exemplary flowchart of a deterministic default naming session as shown in some embodiments of this application; Figure 3 This is an exemplary flowchart of a parallel session processing method shown in some embodiments of this application; Figure 4 This is a schematic diagram of a preferred embodiment of the multi-level jump session management device based on multi-named sessions in this application; Figure 5 This is a schematic diagram of a preferred embodiment of the electronic device of this application; The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0018] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application. All other embodiments obtained by those skilled in the art based on the embodiments in this application without inventive effort are within the scope of protection of this application.

[0019] It should be noted that the use of terms such as "first" and "second" in this application is for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include at least one of those features. Furthermore, the technical solutions of the various embodiments can be combined with each other, but this must be based on the ability of those skilled in the art to implement them. If the combination of technical solutions is contradictory or impossible to implement, such a combination of technical solutions should be considered non-existent and not within the scope of protection claimed in this application.

[0020] Reference Figure 1 The diagram shown is a flowchart illustrating an embodiment of the multi-level jump session management method based on multi-named sessions according to this application. This method is executed by an electronic device, which can be implemented by a software system and / or a hardware system. The multi-level jump session management method based on multi-named sessions includes: Step 101: Maintain multiple naming sessions. Each naming session includes a real-time interaction channel with a remote device based on a remote terminal protocol. Each naming session independently records the current directory, the current user identifier, and the status of the established jump link.

[0021] A named session is a session object with a unique name that is created and managed. This session object is used to carry the command interaction link between the user and the remote device. For example, a named session can be named sess_1 or sess_2, and each named session corresponds to an independent interaction context.

[0022] A real-time interactive channel refers to a bidirectional data communication link established based on a remote terminal protocol, supporting real-time command sending and output feedback. For example, a real-time interactive channel can be a Socket connection established based on the SSH or Telnet protocols, which maintains a persistent connection until the session is actively closed or the network is interrupted.

[0023] A remote terminal protocol is a communication protocol used to transmit character streams and terminal control commands between a local terminal and a remote device. Examples of remote terminal protocols include SSH, Telnet, or Mosh.

[0024] The current directory refers to the working directory path of the remote shell (command interpreter) to which the named session is connected. The current user identifier refers to the username or user identity identifier currently logged into the remote shell to which the named session is connected.

[0025] The jump link state refers to the ordered record of all intermediate network device nodes traversed by a named session from the starting node to the current node. For example, the jump link state can include a complete path record that sequentially passes through jump host A and then jumps to the target server B.

[0026] In some embodiments, the processor maintains multiple named sessions by: allocating an independent session data structure in memory for each named session, the data structure including a session name field, a channel connection object pointer, a current directory string field, a current username field, and a jump link stack; calling the connection interface of the remote terminal protocol to establish a Socket connection with the remote device and associating the connection object with the corresponding session data structure; writing the initial directory and initial username of the remote shell obtained during initialization into the corresponding fields, and initializing the jump link stack to contain only the current remote device node.

[0027] Step 102: Obtain the command text to be executed.

[0028] Command text refers to the command-line instruction string that is entered by the user or generated by the program and is used to execute in a remote shell.

[0029] In some embodiments, the processor obtains the command text to be executed by: receiving a command line string submitted by a user terminal or client program through a standard input interface; removing leading and trailing whitespace characters from the received command line string to obtain clean command text; and temporarily storing the command text in a request receiving buffer for subsequent routing and distribution processing.

[0030] Step 103: When the command text does not specify a target session identifier, the command text is sent to the current default named session, and the command text is sent to the corresponding remote shell for execution through the real-time interaction channel corresponding to the current default named session.

[0031] A target session identifier is a unique identifier used to distinguish a specific session from multiple named sessions. For example, a target session identifier could be the session name string "sess_1" or the session number "2".

[0032] The current default named session refers to the named session that is used by default when no target session is explicitly specified.

[0033] A remote shell is a command interpreter that runs on a remote device to receive and execute user-input commands.

[0034] In some embodiments, the processor sends the command text to the current default named session and then to the corresponding remote shell for execution via the corresponding real-time interactive channel, including: reading the default session pointer field from memory to obtain an object reference of the current default named session; obtaining the output stream object of the real-time interactive channel from the session object; appending a newline character to the obtained command text and writing it to the output stream object, so that the command text directly reaches the standard input of the remote shell via the channel; waiting for the remote shell to execute the command and generate output line by line, and storing the output results in the response buffer of the session.

[0035] In some embodiments, sending the command text to the corresponding remote shell for execution via the real-time interaction channel corresponding to the current default naming session or the specified naming session includes the following operations: S11, when the execution path corresponding to the command text needs to jump across multiple network devices, the user switch command and / or remote login jump command are sent sequentially to the current Shell through the real-time interaction channel.

[0036] The switch user command refers to the command-line instruction executed in the current shell to switch the currently logged-in identity to another user.

[0037] Remote login jump command refers to the command-line instruction executed in the current shell to remotely log in to another network device from the current network device.

[0038] In some embodiments, the processor sequentially sends user switch commands and remote login jump commands to the current Shell via a real-time interactive channel, including: parsing a complete jump path description from the command text, which contains multiple intermediate node addresses arranged in order and the target username to be switched at each node; obtaining an output stream object from the real-time interactive channel of the current named session; writing the user switch command and appending a newline character to the current Shell according to the order of the jump path description, and after the switch command is executed, writing a remote login jump command connecting to the next hop node and appending a newline character to the switched Shell; repeating the above operations until the final target node in the jump path description is reached.

[0039] S12, after each switching command is sent, the raw output stream returned by the switching command is received through the real-time interactive channel.

[0040] Raw output streams refer to the unfiltered and unparsed byte streams of data returned by the remote shell to the local machine through a real-time interactive channel after executing a switch command. For example, raw output streams may contain command echoes, execution results, system prompts, and ANSI control characters and color codes.

[0041] In some embodiments, the processor receiving the raw output stream returned by the switching command through the real-time interactive channel includes: suspending the current thread in the response reading loop of the named session after each switching command is written; repeatedly calling the input stream reading interface of the real-time interactive channel, reading a specified size of byte block each time; concatenating all the read byte blocks into complete raw output stream data in the order of receipt; continuously detecting whether a preset prompt pattern appears at the end of the output stream during the reading process, and terminating the reading loop once the prompt pattern is detected to confirm that the output of the current switching command has been fully returned.

[0042] S13, detect whether the switching command has been executed completely according to the prompt in the original output stream, and send the next switching command after confirming that it has been executed completely, until all the layer-by-layer jumps from the current level to the target level are completed.

[0043] Layer-by-layer hop refers to the complete path switching process that starts from the current network device node, passes through one or more intermediate network device nodes in sequence, and finally reaches the target network device node. For example, layer-by-layer hop can include a two-layer hop process: switching users from jump server A to server B, and then jumping from server B to database server C.

[0044] In some embodiments, the processor detects whether the switching command has been executed based on the prompt in the original output stream, including: after receiving the original output stream, obtaining the prompt regular expression template configured for the current naming session; matching the end character segment of the original output stream with the prompt regular expression template, and if the match is successful, determining that the switching command has been executed; continuing to send the next switching command, and repeating the receiving operation of S12 and the detection operation of S13 until all jump commands have been confirmed to have been executed.

[0045] In some embodiments, detecting whether the switching command has been completed based on the prompt in the original output stream includes: S21, retrieve the preset prompt regular expression template.

[0046] A prompt regular expression template refers to a pre-configured regular expression pattern used to match the prompt string of a remote shell.

[0047] In some embodiments, the processor obtains a preset prompt regular expression template by: reading the prompt regular expression template string from a local configuration file or system environment variable during the naming session initialization phase; compiling the template string into a regular expression object and storing it in the configuration data structure of the current naming session; and directly reading the compiled regular expression object from the data structure when the detection process starts.

[0048] S22, Match the last character of the original output stream with the prompt regular expression template.

[0049] The trailing character refers to a continuous sequence of characters at the end of the raw output stream, the length of which at least covers the length of a typical prompt. For example, the trailing character could be the last 128 characters of the raw output stream, a length sufficient to accommodate the entire contents of a regular prompt.

[0050] In some embodiments, the processor matches the last character of the original output stream with the prompt regular expression template by: extracting a character sequence of a preset length from the end of the original output stream as the last character segment; calling the matching method of the regular expression object, passing the last character segment as an input parameter; obtaining the boolean value returned by the matching method as the matching result and recording the result in the current detection context.

[0051] In other embodiments, the processor matching the last character of the original output stream with the prompt regular expression template further includes: determining the total length of the original output stream before truncating the last character; if the total length is less than a preset truncation length, then using the entire original output stream as the last character segment for matching; using a multi-line matching mode during matching, so that the regular expression can scan across multiple lines and locate the position of the prompt; and recording the contents of the capture group when a match is successful for use in subsequent extraction of host information and user information.

[0052] S23. If the match is successful, the switching command is considered to have been executed.

[0053] S24, if the match fails, the original output stream is reversed and the candidate string after the last newline character is extracted. The ANSI control characters in the candidate string are removed and used as the candidate prompt.

[0054] Reverse character scanning refers to a scanning method that traverses each character backward from the end of the original output stream. For example, reverse character scanning can be a byte-by-byte traversal performed from the end of the output stream towards the beginning.

[0055] The tail candidate string refers to the target substring that may contain prompt information, which is extracted from the last newline character in the original output stream.

[0056] ANSI control characters are a set of non-printable character sequences embedded in a text stream used to control terminal display attributes, including color codes, cursor movement instructions, and font style instructions.

[0057] The candidate prompt refers to the plain text prompt string obtained by extracting it from the end of the original output stream and stripping it from ANSI control characters.

[0058] In some embodiments, the processor performs reverse character scanning of the original output stream and extracts the trailing candidate string by: traversing backward from the last byte position of the original output stream and checking the ASCII code value of each character in turn; recording the position of the first newline character encountered during the traversal, and extracting all characters after that position as the trailing candidate string; processing the trailing candidate string using an ANSI control character filtering function, removing all substrings that conform to the CSI sequence pattern, and combining the remaining visible characters after filtering as candidate prompts.

[0059] S25, based on the edit similarity between the candidate prompt and the template that was most recently successfully matched in the naming session history, determine whether the switching command has been executed.

[0060] In some embodiments, the processor reads the most recently successfully matched template string from the naming session history; calculates the character edit distance between the candidate prompt and the template, where the edit distance represents the minimum number of character edit operations required to convert the candidate prompt into the template; divides the edit distance by the maximum of the lengths of the candidate prompt and the template to obtain a normalized edit distance value; calculates the difference between the normalized edit distance value and the value one as the edit similarity; when the edit similarity is higher than a preset threshold, it is determined that the switching command has been executed and the most recently successfully matched template is taken as the detection result for this time.

[0061] In other embodiments, when the edit similarity is equal to or lower than a preset threshold, the processor further checks whether the naming session is currently in an intermediate state during user switching or remote login. The output stream of the intermediate state may contain password input prompts, confirmation prompts, or authentication result prompts. When an intermediate state is detected, the switching command is marked as incomplete and the detection is re-performed after the next output is received. When the edit similarity matching fails more than a preset number of times consecutively, the switching command is marked as abnormally completed and a detection failure error code is returned.

[0062] In some embodiments, determining whether the toggle command has been completed based on the edit similarity between the candidate prompt and the most recently successfully matched template in the naming session history includes: S31, calculate the number of character editing operations between the candidate prompt and the most recently successfully matched template, the editing operations including character insertion, deletion and replacement.

[0063] The number of character edit operations refers to the minimum total number of single-character edit operations required to convert a candidate prompt string into the most recently successfully matched template string.

[0064] In some embodiments, the processor's calculation of the number of character editing operations between the candidate prompt and the most recently successfully matched template further includes: configuring different weight values ​​for the three editing operations of insertion, deletion, and replacement, wherein the weight of the replacement operation is higher than that of the insertion and deletion operations; using a weighted edit distance algorithm to calculate the number of editing operations, so that when the username or hostname in the prompt changes, a lower similarity score is assigned; and directly returning the length value of the corresponding string as the number of editing operations when the template string length is zero or the candidate prompt length is zero.

[0065] S32, divide the number of editing operations by the maximum length value between the candidate prompt and the most recently successfully matched template to obtain the normalized edit distance, and determine the edit similarity based on the normalized edit distance.

[0066] Normalized edit distance refers to a standardized distance value that maps the number of edit operations to a range of zero to one. This value is used to eliminate the absolute difference in edit distance between strings of different lengths.

[0067] Edit similarity is a quantitative metric used to measure the degree of similarity between two strings, obtained by subtracting the normalized edit distance from the numerical value.

[0068] In some embodiments, the processor divides the number of edit operations by the maximum length value between the candidate prompt and the template to obtain the normalized edit distance and determines the edit similarity, including: obtaining the string length value of the candidate prompt and the string length value of the most recently successfully matched template; taking the larger of the two length values ​​as the maximum length value; dividing the number of character edit operations by the maximum length value to obtain the normalized edit distance; calculating the difference between the normalized edit distance and the value 1, and outputting the difference as the edit similarity.

[0069] S33, when the edit similarity is higher than the preset threshold, the most recently successfully matched template is taken as the detection result and the switching command is determined to be completed.

[0070] The preset threshold refers to the lower limit of similarity that is set in advance to determine whether the edit similarity is sufficient to confirm that the prompt match is successful.

[0071] The test result refers to the matching criteria used in this test process to confirm that the switching command has been executed.

[0072] In some embodiments, when the edit similarity is higher than a preset threshold, the processor uses the most recently successfully matched template as the detection result and determines that the switching command has been executed, which includes: comparing the edit similarity with a preset threshold, the preset threshold being stored in the configuration data structure of the named session; when the comparison result is that the edit similarity is greater than the preset threshold, reading the most recently successfully matched template string from the history as the detection result; marking the status of the current switching command as completed and triggering the sending of the next switching command.

[0073] This embodiment calculates the character edit distance between candidate prompts and historical templates and normalizes it into edit similarity. It uses the comparison result of edit similarity and preset threshold to determine whether the switching command has been completed. This makes the prompt matching mechanism tolerant of prompt character differences caused by dynamic changes in hostnames, user switching or directory updates in remote terminal environments. It solves the problem that the traditional fixed string matching method cannot identify the command completion boundary when the prompt changes after multiple jumps, which leads to the interruption of the automated process.

[0074] In some embodiments, after taking the most recently successfully matched template as the detection result and determining that the switching command has been executed, the method further includes: S41, the candidate prompt is stored as a supplementary template in the temporary cache of the corresponding naming session, and a lifecycle timer is created for the supplementary template and a valid expiration time is set.

[0075] Supplementary templates refer to alternative matching criteria that the processor extracts from candidate prompts and stores in a temporary cache for subsequent prompt matching.

[0076] A temporary cache is a cache area independently allocated for each named session to store dynamically generated supplementary templates. For example, a temporary cache can be an array or linked list structure allocated in the session data structure, which is used to store multiple supplementary templates and their associated metadata.

[0077] A lifetime timer is a timer that starts counting down from the moment the supplementary template is stored in the temporary buffer. This timer controls the lifespan of the supplementary template in the temporary buffer. For example, a lifetime timer can be set to a timeout of 300 seconds, counting down from the moment the template is stored.

[0078] The effective expiration time refers to the absolute expiration time of the supplementary template in the temporary cache area. This time is calculated by adding the preset maximum effective duration to the storage time.

[0079] In some embodiments, the processor stores the candidate prompt as a supplementary template in the temporary buffer of the corresponding naming session, creates a lifecycle timer, and sets a valid expiration time, including: obtaining the candidate prompt string used when calculating edit similarity; encapsulating the candidate prompt string into a supplementary template object, which includes a template text field, a creation timestamp field, and a consecutive failure count field; calling the operating system's timer creation interface to generate a lifecycle timer for the supplementary template, with a duration of a preset survival time window; adding the current system timestamp to the preset maximum valid duration to obtain the valid expiration time, and writing this time into the expiration time field of the supplementary template object; and storing the complete supplementary template object at the end of the temporary buffer of the corresponding naming session.

[0080] S42, before the lifecycle timer expires, when the naming session triggers the completion detection of the switching command again, the tail character of the received original output stream is matched with the supplementary template in the temporary buffer based on edit similarity.

[0081] In some embodiments, the processor checks whether the temporary buffer of the current naming session is empty; if the temporary buffer is not empty, it extracts the trailing character segment from the original output stream and strips the ANSI control characters to obtain the plain text trailing string to be matched; it iterates through all the supplementary templates in the temporary buffer, calculates the edit similarity between the trailing string to be matched and each supplementary template one by one; it selects the supplementary template with the highest edit similarity as the candidate result of this match, and compares the highest similarity value with the preset supplementary template matching threshold. If it is higher than the threshold, it is considered a successful match.

[0082] S43, if the match is successful, determine whether the current time exceeds the valid deadline.

[0083] In some embodiments, the processor reads the value of the valid deadline field from the successfully matched supplementary template object; calls the system time interface to obtain the current system time; compares the current system time with the valid deadline, and if the current system time is greater than the valid deadline, it is determined that the deadline has been exceeded; otherwise, it is determined that the deadline has not been exceeded.

[0084] S44. If the current time has not exceeded the effective deadline, refresh the lifecycle timer and reset the consecutive failure count of the supplementary template to zero.

[0085] The consecutive failure count refers to the cumulative number of times the supplementary template fails to match in multiple consecutive matching attempts. The initial value of this count is zero.

[0086] In some embodiments, the processor refreshes the lifecycle timer and resets the consecutive failure count of the supplementary template to zero when the current time has not exceeded the valid deadline. This includes: after confirming that the current system time has not exceeded the valid deadline, calling the timer reset interface to reset the lifecycle timer to the initial duration and restarting the countdown from the current time; resetting the value of the consecutive failure count field of the supplementary template object to zero; marking the successfully matched supplementary template as active and updating its last successfully matched timestamp field.

[0087] S45, if the current time has exceeded the effective deadline, then discard the supplementary template and remove it from the temporary cache.

[0088] S46. If the matching fails, the consecutive failure count of the supplementary template is incremented by 1. If the consecutive failure count of the supplementary template exceeds the failure count threshold, the supplementary template is removed from the temporary cache. After removal, if the matching is successful again, it is stored in the cache with the initial lifespan.

[0089] The failure count threshold refers to the maximum number of consecutive failures allowed for a supplementary template. When the number of consecutive failures exceeds this threshold, the supplementary template will be deemed invalid and removed from the cache.

[0090] In some embodiments, when a match fails, the processor increments the consecutive failure count of the supplementary template and determines whether it exceeds the failure count threshold. This includes: when the edit similarity matching result is lower than a preset supplementary template matching threshold, incrementing the value of the consecutive failure count field of the supplementary template participating in the matching by 1; reading the consecutive failure count value of the supplementary template and comparing it with the failure count threshold; if the consecutive failure count value is greater than the failure count threshold, removing the supplementary template from the temporary cache and releasing the resources it occupies; and recording the removal event of the supplementary template in the log after removal for reference when diagnosing matching problems later.

[0091] This embodiment dynamically stores temporarily matched candidate prompts into a supplementary template cache and uses a dual expiration control mechanism of lifecycle timer and effective expiration time. This enables the system to automatically learn new prompt patterns and quickly adapt when the prompt format changes due to user switching or remote login. This solves the problem that traditional fixed matching templates cannot accurately identify command completion boundaries when the prompt changes after multiple jumps.

[0092] The scheme employs a cumulative failure count and threshold elimination mechanism. This approach filters out occasional noise prompts and retains consistently appearing valid supplementary templates. Meanwhile, if a removed template matches successfully again, it can be re-stored in the cache with its initial lifecycle. This allows the template library to maintain dynamic self-adaptation while possessing self-repair capabilities. Consequently, it can continuously maintain a high accuracy rate for command completion detection without increasing manual configuration costs, thereby improving the long-term stable operation capability of the automated operation and maintenance system in complex and ever-changing remote terminal environments.

[0093] S14. During the hierarchical jump process, after each jump is completed, the current directory, current user identifier, and jump link status in the current named session record are updated to the status after the jump, so that subsequent commands received can be executed directly using the updated status.

[0094] In some embodiments, after confirming that the user switching command has been executed, the processor parses the prompt from the original output stream of the switching command, extracts the current username from the prompt, and writes it into the user identifier field of the named session; after confirming that the remote login jump command has been executed, the processor parses the target device's prompt from the original output stream of the jump command, extracts the target device's host name and current username from the prompt, and writes them into the host information field and user identifier field of the session, respectively; after each jump is completed, the target node address of the jump is appended to the top of the jump stack of the jump link status field, while keeping the current directory field of the session unchanged until a subsequent directory switching operation triggers an update.

[0095] This embodiment receives the raw output stream in real time after each switching command is sent and accurately detects the completion status of the command based on the prompt. Only after confirmation is completed is the next switching command sent. This ensures that each layer in the multi-layer jump process is reliably confirmed before proceeding to the next layer. This solves the problem of commands being swallowed or escaping incorrectly during transmission caused by the layer-by-layer parsing of multi-layer shells in the traditional nested command method.

[0096] Step 104: When the command text specifies a target session identifier, the command text is sent to the specified named session, and the command text is sent to the corresponding remote shell for execution through the real-time interaction channel corresponding to the specified named session.

[0097] A specified named session refers to the named session that is uniquely pointed to by the target session identifier carried in the command text. For example, when the parameter field of the command text contains session equal to sess_2, sess_2 is the specified named session.

[0098] In some embodiments, the processor sends the command text to a specified named session and then to the corresponding remote shell via the corresponding real-time interactive channel for execution, including: parsing the target session identifier string from the additional parameter field of the command text; using the identifier string as the key to look up and obtain the object reference of the corresponding specified named session in the session hash table; verifying whether the real-time interactive channel of the specified named session is available, and if available, writing the command text to the output stream of the channel; and updating the record information of the specified named session to the most recently used session after the command is sent.

[0099] Step 105: Parse the current prompt of the named session executing the command text, extract the current host information and current user information from the current prompt, and determine the named session executing the command text as the new default named session.

[0100] A prompt is a visible string that a remote shell outputs when a command has finished executing or is waiting for input, indicating the current command-line environment and status.

[0101] The current host information refers to the hostname or network address identifier of the remote device to which the naming session is currently located.

[0102] The current user information refers to the login user account name of the remote shell where the named session is currently located.

[0103] In some embodiments, the processor parses the current prompt of the named session executing the command text and extracts host and user information, including: after the command is executed, reading the tail segment of the output stream from the response buffer of the named session; performing a reverse scan on the tail segment and extracting the string after the last newline character as a candidate prompt; stripping the ANSI control characters from the candidate prompt to obtain the clean prompt text; matching the clean prompt text using a preset regular expression, and extracting the hostname capture group and username capture group from the matching result, which are used as the current host information and the current user information, respectively; and writing the identifier of the named session executing the command into the default session pointer field, thus determining it as the new current default named session.

[0104] This application's embodiments maintain a real-time interaction channel, current directory, user identifier, and jump link status independently for each named session. This ensures that the state of each layer in a multi-level jump process can be persistently maintained. Subsequent commands can reuse the existing jump context without repeating the switching operation, thus solving the problems of repeated authentication and repeated connections caused by the inability to maintain directory and user states in traditional nested command methods. Since the command text is executed directly to the currently located remote shell through the established interaction channel, the phenomenon of quotation marks and special characters being swallowed or escaped incorrectly during multi-level shell nesting parsing is avoided, significantly improving the reliability and success rate of command execution in complex jump scenarios.

[0105] Figure 2 This is an exemplary flowchart illustrating a deterministic default naming session as shown in some embodiments of this application. Figure 2 As shown, the process may include the following operations: Step 201: Obtain the activity status of the real-time interactive channel corresponding to the current default named session.

[0106] The activity status refers to whether the real-time interactive channel is currently in a valid working state where it can normally send and receive data. For example, the activity status can be indicated by whether the channel's socket connection is in the ESTABLISHED state and has not received a FIN or RST message from the peer.

[0107] In some embodiments, the processor obtains the activity status of the real-time interactive channel corresponding to the current default naming session by: reading the connection socket file descriptor of the real-time interactive channel from the data structure of the current default naming session; calling the socket error detection interface of the operating system, passing in the file descriptor and specifying a non-blocking detection mode to check whether there are any pending error events or abnormal events in the connection; and further writing a probe data packet of length 0 bytes to the channel when the operating system interface does not return an error, and determining the actual activity status of the channel based on whether the return value of the write operation is a disconnected pipe error code.

[0108] Step 202: When it is detected that the current default naming session is actively closed or the network connection is interrupted, the current default naming session is confirmed to be invalid.

[0109] Active closure refers to the closure of a real-time interactive channel held by a named session, caused by the local or remote device actively initiating a connection termination process. For example, active closure can be an explicit channel disconnection operation triggered by the user through a session closure command, or an active message sent by the remote device after receiving an exit command.

[0110] In some embodiments, the processor confirms the failure of the current default naming session when it detects that the current default naming session has been actively closed or the network connection has been interrupted. This includes: after obtaining the live state, if the read end of the channel connection socket returns an end-of-file character or the number of bytes read is zero, identifying this phenomenon as the remote end actively closing the connection and marking the corresponding naming session as invalid; after obtaining the live state, if the write operation returns a pipe break error code or a connection timeout error code, identifying this phenomenon as the network connection being interrupted and marking the corresponding naming session as invalid; after confirming the session failure, writing the failure event and the cause of failure to the system log and triggering the post-failure processing procedure.

[0111] Step 203: According to the preset list of live session priorities, select the highest priority naming session from the remaining naming sessions other than the current default naming session as the new default naming session.

[0112] A live session priority list is a predefined sorting list used to indicate the priority order in which a new default session is selected from the remaining live sessions when the default session fails. For example, the live session priority list could be arranged in the order of session creation time as sess_1, sess_2, sess_3, where sess_1 has the highest priority and sess_3 has the lowest priority.

[0113] In some embodiments, the processor reads a list of live session priorities from memory, which stores the identifiers of all named sessions and their corresponding priority order in the form of an array or linked list; removes the identifier of the default named session that has been confirmed as invalid from the list; traverses backward from the head of the list, checks the current liveness status of each session identifier, and selects the first live session identifier that is not currently invalid as the new default named session.

[0114] Step 204: Report the identifier of the new default naming session, and remove the invalid default naming session from the list of live sessions or set it to an unselectable state.

[0115] Reporting refers to the processor's notification action of passing the identification information of the new default named session to the upper-layer caller or management interface. For example, reporting could be achieved by returning a notification message to the client through an inter-process communication mechanism, the message content of which includes the new default named session name sess_2.

[0116] The unselectable state refers to a failed session that still retains its position in the priority list of live sessions but is marked as unselectable.

[0117] In some embodiments, the processor reporting the identifier of the new default naming session and removing or setting the invalid default naming session from the live session priority list includes: generating a state change notification message containing the identifier of the new default naming session, the message including the old default session identifier, the new default session identifier, and the invalidation reason field; sending the notification message to all currently connected clients via an inter-process communication frame protocol; locating the position of the invalid default naming session in the live session priority list, and deciding, according to a preset configuration policy, to remove the entry from the list or set the optional flag of the entry to non-optional.

[0118] This application embodiment obtains the activity status of the default named session channel in real time and automatically selects a new default session according to a preset priority list when it detects active closure or network connection interruption. This avoids the problem that commands without a specified session cannot be routed and executed due to the disconnection of a single session channel, requiring manual intervention to re-establish the connection and switch the session context.

[0119] Figure 3 This is an exemplary flowchart of a parallel session processing method shown in some embodiments of this application. Figure 3 As shown, the process may include the following operations: Step 301: Configure an independent command execution lock and a command request queue associated with the command execution lock for each named session.

[0120] A command execution lock is a synchronization primitive used to control the serial execution of command text within the same named session. This lock allows only one execution thread to hold and execute the command sending operation at any given time. For example, a command execution lock can be a mutex or a binary semaphore, and its states include locked and unlocked states.

[0121] A command request queue is a first-in, first-out (FIFO) data structure used to temporarily store the text of commands to be executed. This queue is associated with a command execution lock for a specific named session. For example, a command request queue can be a blocking queue implemented as an array or a linked list, with the first element being the earliest arriving command request to be processed.

[0122] In some embodiments, configuring an independent command execution lock and a command request queue associated with the command execution lock for each named session includes: allocating a mutex object for the named session when the session is created, the mutex object containing a lock identifier field and a current holder thread identifier field; initializing a command request queue object in the same named session's data structure, the queue object containing a head pointer, a tail pointer, and a queue length counter; and storing the pointers to the mutex object and the command request queue object in the same session data structure, so that the two are bound together through the data structure.

[0123] Step 302: When the same naming session receives multiple command texts to be executed from different clients, the multiple commands are stored in the command request queue of the naming session in the order of receipt time, and an incrementing sequence number is assigned to each command request.

[0124] The sequence number is an integer value that is assigned in ascending order according to the order in which command requests arrive at the processor. It is used to uniquely identify the arrival order of each command request in the named session request queue.

[0125] In some embodiments, the processor stores multiple commands sequentially into the command request queue of the named session according to the order of their reception time and assigns an incrementing sequence number to each command request, including: after extracting the command text to be executed from the frame protocol messages of multiple clients, identifying the target session identifier specified by the command text; encapsulating the command text into a command request object, which includes a command text field, a source client identifier field, a reception timestamp field, and a sequence number field; invoking a system atomic operation to increment the global sequence number counter of the named session, and assigning the incremented value to the sequence number field of the current command request object; and inserting the command request objects into the tail of the command request queue of the named session in ascending order of their sequence numbers.

[0126] Step 303: Acquire the command execution lock before retrieving the head command from the command request queue by the execution thread.

[0127] An execution thread is a worker thread in the processor used to perform command dispatch and sending operations. For example, an execution thread can be any idle worker thread in the processor's thread pool that is scheduled to perform the operation of retrieving commands from the command request queue and sending them.

[0128] In some embodiments, the processor acquires the command execution lock before retrieving the head command from the command request queue via the execution thread, including: when triggering the execution thread to execute the command sending task, calling the locking interface of the mutex lock at the task entry point to attempt to acquire the command execution lock associated with the command request queue; and using an immediate return attempt locking method when calling the locking interface of the mutex lock, which does not block the current thread but directly returns a boolean value indicating whether the lock was successful.

[0129] Step 304: If the command execution lock is already held by another execution thread, the current execution thread enters a blocked waiting state until the command execution lock is released.

[0130] The blocked waiting state refers to the state in which the executing thread suspends execution and enters a sleep state when it fails to successfully acquire the command execution lock.

[0131] In some embodiments, when the processor causes the current executing thread to enter a blocked waiting state until the command execution lock is released when it is already held by another executing thread, the following steps are taken: when the locking attempt fails and the return value is that the lock is already held by another thread, the blocking locking interface of the mutex is called to suspend the current executing thread on the waiting queue of the mutex; when the executing thread holding the lock completes the command sending and releases the lock, the next thread in the waiting queue is awakened by the operating system kernel or thread library; after being awakened, the thread re-attempts to acquire the lock, and if it successfully acquires the lock, it continues to execute the subsequent steps of the command to remove the head of the queue.

[0132] Step 305: After successfully acquiring the command execution lock, retrieve the command text with the smallest sequence number from the command request queue, and send the command text to the corresponding remote shell for execution through the real-time interaction channel of the named session.

[0133] In some embodiments, after successfully acquiring the command execution lock, the processor retrieves the first command request object from the head of the command request queue associated with the lock; reads the sequence number field and command text field from the command request object; obtains the output stream object of the real-time interactive channel from the current named session; appends a newline character to the command text and writes it to the output stream object, so that the command text is directly connected to the standard input of the remote shell via the channel; and releases the command execution lock after the command is sent, so that other execution threads in the waiting queue can acquire the lock and process the next command request in the queue.

[0134] This application's embodiments configure independent command execution locks and command request queues for each named session. When multiple clients concurrently submit commands to the same session, they are executed serially according to the order of receipt time. This avoids the problem of output stream interleaving and command confusion caused by multiple clients simultaneously writing commands to the same real-time interactive channel. It also solves the problem of chaotic output results and the inability to programmatically manage parallel operations when multiple terminals operate independently in parallel, due to interleaved command execution. Because the blocking and waiting mechanism of the command execution lock, combined with the incremental allocation of sequence numbers, ensures that commands in the same session are executed strictly in the order of arrival without overwriting or out of order, thus making it possible for multiple clients to share the same session. This significantly improves session reuse efficiency and operational security in multi-user or multi-task scenarios.

[0135] Reference Figure 4 The diagram shown is a functional module schematic of the multi-level jump session management device 100 based on multi-named sessions of this application.

[0136] The multi-level jump session management device 100 based on multi-named sessions described in this application is installed in an electronic device. Depending on the functions implemented, the multi-level jump session management device 100 includes a maintenance module 110, an acquisition module 120, a first sending module 130, a second sending module 140, and a parsing module 150. These modules can also be referred to as units, which are a series of computer program segments that can be executed by the processor of an electronic device and perform a fixed function, and are stored in the memory of the electronic device.

[0137] In this embodiment, the functions of each module / unit are as follows: The maintenance module 110 is used to maintain multiple naming sessions. Each naming session includes a real-time interaction channel with a remote device based on a remote terminal protocol, and each naming session independently records the current directory, the current user identifier, and the status of the established jump link. Module 120 is used to obtain the text of the command to be executed; The first sending module 130 is used to send the command text to the current default named session when the command text does not specify a target session identifier, and send the command text to the corresponding remote shell for execution through the real-time interaction channel corresponding to the current default named session; The second sending module 140 is configured to send the command text to a specified named session when the command text specifies a target session identifier, and to send the command text to the corresponding remote shell for execution through the real-time interaction channel corresponding to the specified named session; and The parsing module 150 is used to parse the current prompt of the named session executing the command text, extract the current host information and current user information from the current prompt, and determine the named session executing the command text as the new default named session.

[0138] The specific implementation of the multi-level jump session management device based on multi-named sessions in this application is largely the same as the specific implementation of the multi-level jump session management method based on multi-named sessions described above, and will not be repeated here.

[0139] Reference Figure 5 The diagram shown is a schematic representation of a preferred embodiment of the electronic device of this application.

[0140] The electronic device includes a processor 111, a communication interface 112, a memory 113, and a communication bus 114, wherein the processor 111, the communication interface 112, and the memory 113 communicate with each other through the communication bus 114. The memory 113 is used to store computer programs, such as a multi-level jump session management program based on multi-named sessions; In some embodiments, the processor 111 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip. The processor 111 is typically used to control the overall operation of the electronic device, such as performing data interaction or communication-related control and processing. In this embodiment, the processor 111 is used to run program code stored in the memory 113 or process data.

[0141] The communication interface 112 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface). The communication interface 112 may also be used to establish a communication connection between the electronic device and other electronic devices.

[0142] The memory 113 includes at least one type of readable storage medium, including flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 113 may be an internal storage unit of the electronic device, such as the hard disk or memory of the electronic device. In other embodiments, the memory 113 may also be an external storage device of the electronic device, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc. of the electronic device. Of course, the memory 113 may include both internal storage units and external storage devices of the electronic device. In this embodiment, the memory 113 is typically used to store the operating system and various computer programs installed on the electronic device, such as the program code of a multi-level jump session management program based on multi-named sessions. In addition, the memory 113 can also be used to temporarily store various types of data that have been output or will be output.

[0143] Figure 5 Only an electronic device having a processor 111, a communication interface 112, a memory 113 and a communication bus 114 is shown. However, it should be understood that it is not required to implement all of the components shown, and more or fewer components may be implemented instead.

[0144] In one embodiment of this application, when the processor 111 executes a program stored in the memory 113, it implements the multi-level jump session management method based on multiple named sessions provided in any of the foregoing method embodiments, including: Maintain multiple naming sessions, each of which includes a real-time interaction channel with a remote device based on a remote terminal protocol, and each of which independently records the current directory, the current user identifier, and the status of the established jump links; Get the text of the command to be executed; When the command text does not specify a target session identifier, the command text is sent to the current default named session, and then sent to the corresponding remote shell for execution through the real-time interaction channel corresponding to the current default named session; When the command text specifies a target session identifier, the command text is sent to the specified named session, and then, through the real-time interaction channel corresponding to the specified named session, the command text is sent to the corresponding remote shell for execution; and The current prompt of the named session executing the command text is parsed, the current host information and current user information are extracted from the current prompt, and the named session executing the command text is determined as the new default named session.

[0145] For a detailed explanation of the above steps, please refer to the above. Figure 1 A flowchart illustrating an embodiment of a multi-level jump session management method based on multi-named sessions.

[0146] Furthermore, this application also proposes a computer-readable storage medium that is both non-volatile and volatile. This computer-readable storage medium is any one or any combination of several of the following: hard disk, multimedia card, SD card, flash memory card, SMC, read-only memory (ROM), erasable programmable read-only memory (EPROM), portable compact disc read-only memory (CD-ROM), USB memory, etc. The computer-readable storage medium includes a data storage area and a program storage area. The program storage area stores a multi-level jump session management program based on multiple named sessions. When executed by a processor, the multi-level jump session management program based on multiple named sessions performs the following operations: Maintain multiple naming sessions, each of which includes a real-time interaction channel with a remote device based on a remote terminal protocol, and each of which independently records the current directory, the current user identifier, and the status of the established jump links; Get the text of the command to be executed; When the command text does not specify a target session identifier, the command text is sent to the current default named session, and then sent to the corresponding remote shell for execution through the real-time interaction channel corresponding to the current default named session; When the command text specifies a target session identifier, the command text is sent to the specified named session, and then, through the real-time interaction channel corresponding to the specified named session, the command text is sent to the corresponding remote shell for execution; and The current prompt of the named session executing the command text is parsed, the current host information and current user information are extracted from the current prompt, and the named session executing the command text is determined as the new default named session.

[0147] The specific implementation of the computer-readable storage medium in this application is largely the same as the specific implementation of the multi-level jump session management method based on multi-named sessions described above, and will not be repeated here.

[0148] It should be noted that the sequence numbers of the embodiments in this application are merely for descriptive purposes and do not represent the superiority or inferiority of the embodiments. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover a non-exclusive inclusion, such that a process, apparatus, article, or method that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, apparatus, article, or method. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, apparatus, article, or method that includes that element.

[0149] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware simulation platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes several instructions to cause a terminal device to execute the methods described in the various embodiments of this application.

[0150] The above are merely preferred embodiments of this application and do not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.

Claims

1. A multi-level redirection session management method based on multi-named sessions, characterized in that, The method includes: Maintain multiple naming sessions, each of which includes a real-time interaction channel with a remote device based on a remote terminal protocol, and each of which independently records the current directory, the current user identifier, and the status of the established jump links; Get the text of the command to be executed; When the command text does not specify a target session identifier, the command text is sent to the current default named session, and then sent to the corresponding remote shell for execution through the real-time interaction channel corresponding to the current default named session; When the command text specifies a target session identifier, the command text is sent to the specified named session, and then sent to the corresponding remote shell for execution through the real-time interaction channel corresponding to the specified named session; The current prompt of the named session executing the command text is parsed, the current host information and current user information are extracted from the current prompt, and the named session executing the command text is determined as the new default named session.

2. The multi-level jump session management method based on multiple named sessions as described in claim 1, characterized in that, The step of sending the command text to the corresponding remote shell for execution via the real-time interaction channel corresponding to the current default naming session or the specified naming session includes: When the execution path corresponding to the command text needs to jump across multiple network devices, the user switch command and / or remote login jump command are sent sequentially to the current Shell through the real-time interaction channel. After each switching command is sent, the raw output stream returned by the switching command is received through the real-time interactive channel; The system detects whether the switching command has been completed based on the prompt in the original output stream, and sends the next switching command only after confirming that the command has been completed, until all the jumps from the current level to the target level are completed. During the hierarchical hop process, after each hop is completed, the current directory, current user ID, and hop link status in the current named session record are updated to the hopped status, so that subsequent commands can be executed directly using the updated status.

3. The multi-level jump session management method based on multiple named sessions as described in claim 2, characterized in that, The step of detecting whether the switching command has been executed completely based on the prompt in the original output stream includes: Retrieve the preset prompt regular expression template; Match the last character of the original output stream with the prompt regular expression template; If a match is found, the switching command is considered to have been executed successfully. If the match fails, the original output stream is reversed and the candidate string after the last newline character is extracted. The ANSI control characters in the candidate string are removed and used as the candidate prompt. Based on the edit similarity between the candidate prompt and the template that was most recently successfully matched in the naming session history, it is determined whether the toggle command has been executed.

4. The multi-level jump session management method based on multi-named sessions as described in claim 3, characterized in that, The step of determining whether the toggle command has been completed based on the edit similarity between the candidate prompt and the most recently successfully matched template in the naming session history includes: Calculate the number of character editing operations between the candidate prompt and the most recently successfully matched template, the editing operations including character insertion, deletion and replacement; The normalized edit distance is obtained by dividing the number of edit operations by the maximum length of the candidate prompt and the most recently successfully matched template, and the edit similarity is determined based on the normalized edit distance. When the edit similarity is higher than a preset threshold, the most recently successfully matched template is taken as the detection result and the switching command is determined to have been executed.

5. The multi-level jump session management method based on multi-named sessions as described in claim 4, characterized in that, After using the most recently successfully matched template as the detection result and determining that the switching command has been executed, the method further includes: The candidate prompts are stored as supplementary templates in the temporary cache of the corresponding naming session, and a lifecycle timer is created for the supplementary templates and a valid expiration time is set. Before the lifecycle timer expires, when the naming session triggers the completion detection of the switching command again, the tail character of the received original output stream is matched with the supplementary template in the temporary buffer based on edit similarity. If a match is successful, determine whether the current time exceeds the valid deadline. If the current time has not exceeded the effective deadline, then refresh the lifecycle timer and reset the consecutive failure count of the supplementary template to zero; If the current time has exceeded the effective deadline, the supplementary template is discarded and removed from the temporary cache. If a match fails, the consecutive failure count of the supplementary template is incremented by 1. If the consecutive failure count of the supplementary template exceeds the failure count threshold, the supplementary template is removed from the temporary cache. After removal, if a match is successful again, it is stored back in the cache with the initial lifespan.

6. The multi-level jump session management method based on multiple named sessions as described in claim 1, characterized in that, Before sending the command text to the current default naming session, the method further includes: Obtain the activity status of the real-time interactive channel corresponding to the current default named session; When it is detected that the current default naming session is actively closed or the network connection is interrupted, it is confirmed that the current default naming session is invalid. According to the preset list of live session priorities, select the highest priority naming session from the remaining naming sessions other than the current default naming session as the new default naming session; The identifier of the new default naming session is reported, and the invalid default naming session is removed from the list of live sessions or set to an unselectable state.

7. The multi-level jump session management method based on multiple named sessions as described in claim 1, characterized in that, When command texts to be executed are simultaneously obtained from multiple clients, the method further includes: Configure an independent command execution lock and a command request queue associated with the command execution lock for each named session; When the same naming session receives multiple command texts to be executed from different clients, the multiple commands are stored in the command request queue of the naming session in the order of receipt time, and each command request is assigned an incrementing sequence number. Acquire the command execution lock before retrieving the head command from the command request queue by the execution thread; If the command execution lock is already held by another execution thread, the current execution thread enters a blocked waiting state until the command execution lock is released; After successfully acquiring the command execution lock, the command text with the smallest sequence number is retrieved from the command request queue and sent to the corresponding remote shell for execution through the real-time interaction channel of the named session.

8. A multi-level jump session management device based on multi-named sessions, characterized in that, The device includes: The maintenance module is used to maintain multiple naming sessions. Each naming session includes a real-time interaction channel with a remote device based on a remote terminal protocol, and each naming session independently records the current directory, the current user identifier, and the status of the established jump links. The acquisition module is used to acquire the text of the command to be executed; The first sending module is used to send the command text to the current default named session when the command text does not specify a target session identifier, and send the command text to the corresponding remote shell for execution through the real-time interaction channel corresponding to the current default named session; The second sending module is configured to send the command text to a specified named session when the command text specifies a target session identifier, and to send the command text to the corresponding remote shell for execution via the real-time interaction channel corresponding to the specified named session; and The parsing module is used to parse the current prompt of the named session executing the command text, extract the current host information and current user information from the current prompt, and determine the named session executing the command text as the new default named session.

9. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; When a processor executes a program stored in memory, it implements the multi-level jump session management method based on multiple named sessions as described in any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the multi-level jump session management method based on multiple named sessions as described in any one of claims 1 to 7.