Here is my version of script that is first trying to get docker stats container wise but and then moves onto the expect part to start a tester tool to fetch stats by pressing the x key. Script is as follows:
#!/bin/bash
#!/usr/bin/expect -f
docker stats --no-stream --format "{\"container\": \"{{ .Name }}\", \"memory\": { \"raw\": \"{{ .MemUsage }}\", \"percent\": \"{{ .MemPerc }}\"}, \"cpu\": \"{{ .CPUPerc }}\"}"
#docker cp new.sh main:/app/aicore/state_tools/
docker exec main bash -c "cd aicore/state_tools; pwd;
/usr/bin/expect << 'EOF'
set timeout -1
for { set i 0 } { $i < 300000 } { incr i } {
spawn /app/aicore/state_tools/ss_tester
expect "Exit"
send -- "x\r"
expect "press"
send -- "\s03"
sleep 300
}
EOF"
The error I get is as follows: missing operand at @ in expression " @< 300000 " (parsing expression " < 300000 ") invoked from within "for { set i 0 } { < 300000 } { incr i } { spawn /app/aicore/state_tools/ss_tester expect Exit send -- xr expect press send -- s03 sleep 300 }"
Can someone please guide what am I doing wrong in the code?