I'm using the following expect(1) script to receive a list of users on a Teamspeak server using the Telnet Server Query.
#!/usr/bin/expect
# Spawn TELNET
spawn telnet example.com 10000
expect "TS3"
# Login
send "login $USER $PASS\r"
# Set serverID
send "use sid=$SSID\r"
expect "error id=0 msg=ok"
# Get clients
send "clientlist\r"
This produces an output like this:
clid=512 cid=3 client_database_id=4 client_nickname=User1 client_type=1|clid=486 cid=3 client_database_id=26 client_nickname=User2 client_type=0
Then, I can use the following code to get the client id (clid=*) of the first user;
# Get clients
send "clientlist\r"
expect -re "clid=(\\d+) "
set clid $expect_out(1,string)
puts "$clid"
# Output: 512
Questions:
- How can I get a list of all the client ids (clid=*)
- Can I loop over them using a
for
/foreach
?
I've tried to use the accepted answer in this question: How do I extract all matches with a Tcl regex?, however I'm so far unable to apply it on the output of a send
, instead of a variable