You are not logged in.

#1 2013-09-30 08:11:02

SteveDeFacto
Member
Registered: 2013-08-16
Posts: 158

Search terminal output for string

Essentially, I am trying to search the output of a telnet connection to mopidy to determine if "state: play" is in the output. However, it appears as though I am only searching the first line. Here is my code:

#!/bin/bash
output=$(expect -c '
spawn telnet localhost 6600
sleep 1
send "status\r"
')
if [[ "$output" =~ "*state: play*" ]]
then
    echo "yes"
else
    echo "no"
fi

Last edited by SteveDeFacto (2013-09-30 08:12:38)

Offline

#2 2013-09-30 08:15:37

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: Search terminal output for string

It would be helpful if you included the output of the command so people can see what text needs to be processed.


Moving to Programming & Scripting...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2013-09-30 08:26:05

SteveDeFacto
Member
Registered: 2013-08-16
Posts: 158

Re: Search terminal output for string

jasonwryan wrote:

It would be helpful if you included the output of the command so people can see what text needs to be processed.


Moving to Programming & Scripting...

telnet localhost 6600
Trying ::1...
Connected to localhost.
Escape character is '^]'.
OK MPD 0.17.0
status
volume: 100
repeat: 0
random: 0
single: 0
consume: 0
playlist: 148
playlistlength: 43
xfade: 0
state: play
song: 13
songid: 115
time: 63:228
elapsed: 63.003
bitrate: 160
OK

However, when I echo $output all I see is "telnet localhost 6600". Not sure if that is because echo can only display one line or I am capturing only one line.

Last edited by SteveDeFacto (2013-09-30 08:28:49)

Offline

#4 2013-09-30 09:17:14

SteveDeFacto
Member
Registered: 2013-08-16
Posts: 158

Re: Search terminal output for string

It seems that the problem is that the expect/spawn command is preventing the terminal output. I tried the -console flag but it returns an error, "parent: sync byte write: broken pipe."

Offline

Board footer

Powered by FluxBB