Sponsored Content
Top Forums Shell Programming and Scripting Expect pattern matching in the command output Post 303013979 by marsala on Saturday 3rd of March 2018 01:22:08 AM
Old 03-03-2018
Expect pattern matching in the command output

This is the command output need to be matched:
[snr_core.serconsole.con info] Telnet console listening to port 42365.
(the port number changes every time)

Code to test it:
=======================================
Code:
#!/tools/AGRtools/bin/expect
exp_internal 1

set timeout 10

spawn bash
set bashId $spawn_id

send_user -i $bashId "\n"
send_user -i $bashId "\[snr_core.serconsole.con info\] Telnet console listening to port 42365.\n"
expect -i $bashId -re "\[snr_core.serconsole.con info\] Telnet console listening to port \[0-9]*\." {send_user "The output is $expect_out(0,string)\n"}

====================================
It send_user a line, the same as the expected output, then catch it and display $expect_out(0,string).

This is the debug output:
Code:
spawn bash
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {115854}

[snr_core.serconsole.con info] Telnet console listening to port 42365.

expect: does "" (spawn_id exp4) match regular expression "[snr_core.serconsole.con info] Telnet console listening to port [0-9]*."? no
antxec10:/user_workspace/master/tools/AcpTestTool:
expect: does "\u001b]0;ecuser@antxec10:~/user_workspace/master/tools/AcpTestTool\u0007\u001b[?1034hantxec10:/user_workspace/master/tools/AcpTestTool:" (spawn_id exp4) match regular expression "[snr_core.serconsole.con info] Telnet console listening to port [0-9]*."? no
expect: timed out

I also tried different escape sequences, brace, double/triple backslash etc., no luck.

Appreciate for any help


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 03-03-2018 at 05:13 AM.. Reason: Added CODE tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

using command line arguments as columns for pattern matching using awk

Hi, I wish to use a column, as inputted by a user from command line, for pattern matching. awk file: { if($1 ~ /^8/) { print $0> "temp2.csv" } } something like this, but i want '$1' to be any column as selected by the user from command line. ... (1 Reply)
Discussion started by: invinclible0009
1 Replies

2. UNIX for Dummies Questions & Answers

how to save the output of command in tcl/expect

hi, everyone: I just wonder how to save the output of command, I mean everything, save as a string into a variable. another question is I try to ls the details of a directory, but it works in the shell, not in the script. for example code: ls -ltr *se100* | grep ^- | tail -1 | awk '... (1 Reply)
Discussion started by: allenxiao7
1 Replies

3. AIX

matching pattern in 'ps' command

Hi all, I have two instance of jboss (jboss and jboss2). In a shell script that I am writing, I need to grep for each instance of jboss. If i use ps -ef|grep 'jboss', it will also return the process for my second instance of jboss, which is jboss2. Can someone tell me how can i specify the... (1 Reply)
Discussion started by: haroon_a
1 Replies

4. HP-UX

pgrep doesn't perform full command line pattern matching

Hi! I need to get PID of some particular process and I wonder if I can use pgrep tool for this purpose. The problem is that pgrep doesn't perform pattern matching on the whole command line, even if I use -f key. Parsing output of ps command is not quite convenient... Also deamon, which PID I need... (2 Replies)
Discussion started by: Sapfeer
2 Replies

5. Shell Programming and Scripting

Understanding pattern matching used in a grep command

I have the following code. I want to remove the --sort=num/num/... and am using grep to exclude it as shown below: I have a bit of problem figuring out the use of - at the front echo "--sort=4/5/6" | grep -ivE '-((sort|group)=+/+(/+)*)$' Now suppose I want to remove --quiet I can... (7 Replies)
Discussion started by: kristinu
7 Replies

6. Shell Programming and Scripting

Need one liner to search pattern and print everything expect 6 lines from where pattern match made

i need to search for a pattern from a big file and print everything expect the next 6 lines from where the pattern match was made. (8 Replies)
Discussion started by: chidori
8 Replies

7. Shell Programming and Scripting

Expect Script - Pattern Matching Trouble

I am still learning expect, For the below script I always get This is True as the answer. Tried to debug and does not make sense to me. Not sure, where I am doing the mistake. Need Help! - Thanks #!/usr/bin/expect -f set timeout 10 spawn -noecho bash expect { *$* } send "test -d... (3 Replies)
Discussion started by: rmsagar
3 Replies

8. Shell Programming and Scripting

Expect - assigning UNIX command output to a variable

Hi, I'm writing a script that connects through ssh (using "expect") and then is supposed to find whether a process on that remote machine is running or not. Here's my code (user, host and password are obviously replaced with real values in actual script): #!/usr/bin/expect set timeout 1... (3 Replies)
Discussion started by: oseri
3 Replies

9. Shell Programming and Scripting

Pattern Matching and creating output

HI Unix Forum, My requirement I have two set of Patterns UBA and CIE for which different Phases are there which will have Start and End time. They are not in same order. I want the o/p in the below mentioned format. Eg: Mangolia Alien 03:04:56 Phase 0 started (10... (5 Replies)
Discussion started by: TechGyaann
5 Replies

10. Shell Programming and Scripting

UNIX command to get the latest file and also matching pattern

we want to fetch the latest file in a given directory and also the file name should match the below pattern Example file name ->hrdata-2015-10-13-16-45-26.xml(2015-10-13-16-45-26- it is not current timestamp, we just need to check for the pattern) We expect the file will have the... (3 Replies)
Discussion started by: vishwanath001
3 Replies
dp(4)							     Kernel Interfaces Manual							     dp(4)

NAME
dp - dedicated ports file used by DDFA software and Telnet port identification feature DESCRIPTION
The file has two uses: The file is used by the Datacommunications and Terminal Controller Device File Access (DDFA) software to allow terminal server ports to be programmatically accessed from HP-UX applications in the same way as devices connected directly to the HP-UX sys- tem. It contains a one-line entry for each configured terminal server port. The file contains the information the DDFA software needs to set up and manage an outbound connection to a specified terminal server port. The file is parsed by the Dedicated Port Parser which spawns an Outbound Connection Daemon for each outbound connection specified in the file. The file is used by the HP-UX telnet daemon to identify the calling port and board of a telnet connection from an HP Datacommuni- cations and Terminal Controller (DTC). At connection time, the host negotiates the telnet environment option and the DTC replies with the port and board number of the connecting device. maps the port and board numbers to the well-known name for the device, which has previously been con- figured in the file. Datacommunications and Terminal Controller Device File Access For outbound connections, an entry should have the following format: The exact details of each field are given below. Telnet Port Identification To configure the file for using the Telnet port identification feature, the default file should be copied to a new file and the copy con- figured with the appropriate values for the incoming connections. The recommended procedure is to create a directory to hold the file and the modified port configuration files. An entry for this purpose should have the following format: The exact details of each field are given below. Configuration Information There are three ways to specify a terminal server port: o Explicitly specify its IP address. o Specify the node name or the IP address of the DTC then specify the board and port. o Specify the node name or the IP address of the terminal server and the TCP port service address of the port. Comments in the file can be appended by starting them with a character. Everything after the is ignored by the parser. Fields in the file are separated by space characters. See ddfa(7) for more information on how to configure the DDFA software. The fields of an entry of the file are as follows: dtc_name This field is the node name or the IP address of the terminal server being accessed or the IP address of the port on the terminal server. A node name must be defined in a name database. This field contains the terminal server port address with the parts separated by the character. It is not necessary to pad the values with leading zeros. The port address is not checked by but is checked by Valid values are 0 through 7 for board, and 0 through 31 for port (these restrictions do not apply if the TCP port service address is specified instead). If the dtc_name field explicitly defines the node name or the IP address of the terminal server port, the value in the field must be (use or If the field is of the form where n is a decimal number, n is assumed to be the TCP port service address and it is used when the connection is established. pseudonym This field is the absolute path of the device file known to the system and the end-user application. The device file name portion of the path name is limited to 14 characters. pc_file_path This field is the path to a port configuration file which contains the configuration information for the terminal server port. This field is mandatory for outbound connections as uses the presence of this field as its flag to spawn a daemon for the entry. log_level This field is the logging level for the particular and it determines the severity of messages sent to The logging levels (and how they relate to system logging levels) are as follows: Log only LOG_CRIT messages. Log only LOG_CRIT and LOG_ERR messages. Log only LOG_CRIT, LOG_ERR, and LOG_WARNING messages. Log all messages. It is optional and may only be specified for outbound connections. If it is omitted, the logging level is set to 1. EXAMPLES
The following examples illustrate file entry syntax. A printer is connected to port 1 of board 3 of a DTC with the IP address 11.234.87.123. The device attached to the port can be accessed with the HP-UX spooler by using the device file A printer is connected to a terminal server port with IP address 11.234.87.124. The field contains The device attached to the port can be accessed with the HP-UX spooler by using the device file A printer is connected to a port accessed with TCP port service address 5001 of a terminal server with the IP address 11.234.87.215. The device attached to the port can be accessed with the HP-UX spooler by using the device file A terminal is connected to port 1 of board 2 of a DTC with the IP address 11.234.87.215 and wishes to use Telnet port identification. WARNINGS
In order to ensure that commands (such as ps) display the correct device file name (that is, the pseudonym), all pseudonyms should be placed into the directory If pseudonyms are not specified for placement in this directory, the correct display of device file names with many commands is not guaranteed. In addition, in order to ensure that commands (such as and work correctly, each pseudonym must be unique in its first 17 characters (including the directory prefix If pseudonyms are not unique in their first 17 characters, the correct functioning of many commands is not guaranteed. FILES
SEE ALSO
dpp(1M), ocd(1M), ocdebug(1M), syslog(3C), pcf(4), ddfa(7). dp(4)
All times are GMT -4. The time now is 07:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy