Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Help in parsing expect command's output and remove new lines EXPECT scripting Post 303045880 by Chubler_XL on Thursday 16th of April 2020 07:09:40 PM
Old 04-16-2020
Your RE is matching the local echo of hostname -i\r sent earlier. Try this RE .*\r\n(.*)\r\n#

For example:
Code:
set timeout 3
log_user 0
expect "# " {send "hostname -i\r"}
expect {
   -re ".*\r\n(.*)\r\n# " {set addr1 $expect_out(1,string)}
   timeout { puts "Timeout looking for TCP/IP address\n"; }
}
send "exit\r"

puts "TCP/IP address is: $addr1"

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expect: Parsing/evaluating lines of numbers

There *has* to be an elegant way to do this in Expect... I have a command that returns lines of numbers. Like: prompt% mycommand --loop=5 9 4956 4951 4951 4956 9 4960 4951 4951 4956 9 4956 4951 4951 4956 9 4956 4951 4951 4956 9 4956 4951 4951 4956 prompt% All numbers must be... (0 Replies)
Discussion started by: kajkaj
0 Replies

2. Shell Programming and Scripting

strange expect script behavior, or am i misunderstanding expect scripting?

Hello to all...this is my first post (so please go easy). :) I feel pretty solid at expect scripting, but I'm running into an issue that I'm not able to wrap my head around. I wrote a script that is a little advanced for logging into a remote Linux machine and changing text in a file using sed.... (2 Replies)
Discussion started by: v1k0d3n
2 Replies

3. Shell Programming and Scripting

Need help with Expect script for Cisco IPS Sensors, Expect sleep and quoting

This Expect script provides expect with a list of IP addresses to Cisco IPS sensors and commands to configure Cisco IPS sensors. The user, password, IP addresses, prompt regex, etc. have been anonymized. In general this script will log into the sensors and send commands successfully but there are... (1 Reply)
Discussion started by: genewolfe
1 Replies

4. Shell Programming and Scripting

Expect scripting

Hi I have a working expect script below. The script continues to log cisco router configurations until all the ip addresses in the "routerlist1" has been read. Problem will start to happen when one of the ip address is not reacheable via ssh or telnet. The script will stop to read the rest of the... (2 Replies)
Discussion started by: yano1o14
2 Replies

5. Shell Programming and Scripting

Parsing expect_out using regex in expect script

Hi, I am trying to write an expect script. Being a newbie in expect, maybee this is a silly doubt but i am stuck here. So essentially , i want the o/p of one router command to be captured . Its something like this Stats Input Rx : 1234 Input Bytes : 3456 My expect script looks ... (5 Replies)
Discussion started by: ashy_g
5 Replies

6. Shell Programming and Scripting

Expect scripting

Hello, I tried to use expect to catch information from my nagios and send me a call but i have nothing when i execute the script : 0 - add : account SIP 1 - trext : information from nagios text2wav : conversion text to wav ( text to speech ) pjsua : connection thru the SIP ... (0 Replies)
Discussion started by: acidozik
0 Replies

7. Shell Programming and Scripting

Expect scripting.

I was wondering if I could do this a bit better. another script calls this script and logs into a device, does the relavant "show commands" and then saves those to a file. My problem is that the buffer isn't large enough to the output of some of the commands. here is an excerpt of what i'm... (0 Replies)
Discussion started by: gen1mx6
0 Replies

8. IP Networking

IP and expect scripting

Hi I am new to IP configuration and using expect script I have a requirement like I need to write a expect script that can ssh to a remote machine(linux1) using password which already has IP, once logged inside machine need to reboot remote machine(linux1) and again login to same remote... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

9. Programming

Expect script returning string following a found expect.

I'm fairly new to scripting so this might not be possible. I am using Expect with Cisco switches and need to capture the string after finding the expect request. For example, when I issue "show version" on a Nexus switch, I'm looking to capture the current firmware version: #show version ... (0 Replies)
Discussion started by: IBGaryA
0 Replies
tcpsvd(8)						      System Manager's Manual							 tcpsvd(8)

NAME
tcpsvd - TCP/IP service daemon SYNOPSIS
tcpsvd [-hpEvv] [-c n] [-C n:msg] [-b n] [-u user] [-l name] [-i dir|-x cdb] [ -t sec] host port prog DESCRIPTION
tcpsvd creates a TCP/IP socket, binds it to the address host:port, and listens on the socket for incoming connections. On each incoming connection, tcpsvd conditionally runs a program, with standard input reading from the socket, and standard output writing to the socket, to handle this connection. tcpsvd keeps listening on the socket for new connections, and can handle multiple connections simultaneously. tcpsvd optionally checks for special instructions depending on the IP address or hostname of the client that initiated the connection, see ipsvd-instruct(5). OPTIONS
host host either is a hostname, or a dotted-decimal IP address, or 0. If host is 0, tcpsvd accepts connections to any local IP address. port tcpsvd accepts connections to host:port. port may be a name from /etc/services or a number. prog prog consists of one or more arguments. For each connection, tcpsvd normally runs prog, with file descriptor 0 reading from the network, and file descriptor 1 writing to the network. By default it also sets up TCP-related environment variables, see tcp-envi- ron(5) -i dir read instructions for handling new connections from the instructions directory dir. See ipsvd-instruct(5) for details. -x cdb read instructions for handling new connections from the constant database cdb. The constant database normally is created from an instructions directory by running ipsvd-cdb(8). -t sec timeout. This option only takes effect if the -i option is given. While checking the instructions directory, check the time of last access of the file that matches the clients address or hostname if any, discard and remove the file if it wasn't accessed within the last sec seconds; tcpsvd does not discard or remove a file if the user's write permission is not set, for those files the timeout is disabled. Default is 0, which means that the timeout is disabled. -l name local hostname. Do not look up the local hostname in DNS, but use name as hostname. This option must be set if tcpsvd listens on port 53 to avoid loops. -u [:]user[:group] drop permissions. Set uid and gid to the user's uid and gid, as found in /etc/passwd, before running prog. If user is followed by a colon and a group, set the gid to group's gid, as found in /etc/group, instead of user's gid. If group consists of a colon-sepa- rated list of group names, set the group ids of all listed groups. If user is prefixed with a colon, the user and all group argu- ments are interpreted as uid and gids respectively, and not looked up in the password or group file. All supplementary groups are removed. -c n concurrency. Handle up to n connections simultaneously. Default is 30. If there are n connections active, tcpsvd defers accep- tance of a new connection until an active connection is closed. -C n[:msg] per host concurrency. Allow only up to n connections from the same IP address simultaneously. If there are n active connections from one IP address, new incoming connections from this IP address are closed immediately. If n is followed by :msg, the message msg is written to the client if possible, before closing the connection. By default msg is empty. See ipsvd-instruct(5) for sup- ported escape sequences in msg. For each accepted connection, the current per host concurrency is available through the environment variable TCPCONCURRENCY. n and msg can be overwritten by ipsvd(7) instructions, see ipsvd-instruct(5). By default tcpsvd doesn't keep track of connections. -h Look up the client's hostname in DNS. -p paranoid. After looking up the client's hostname in DNS, look up the IP addresses in DNS for that hostname, and forget about the hostname if none of the addresses match the client's IP address. You should set this option if you use hostname based instructions. The -p option implies the -h option. -b n backlog. Allow a backlog of approximately n TCP SYNs. On some systems n is silently limited. Default is 20. -E no special environment. Do not set up TCP-related environment variables. -v verbose. Print verbose messsages to standard output. -vv more verbose. Print more verbose messages to standard output. SEE ALSO
ipsvd(7), sslsvd(8), udpsvd(8), ipsvd-instruct(5), ipsvd-cdb(8), sslio(8) http://smarden.org/ipsvd/ AUTHOR
Gerrit Pape <pape@smarden.org> tcpsvd(8)
All times are GMT -4. The time now is 01:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy