You are not logged in.
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
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...
Offline
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
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