-4

我需要做什么:

  1. 在命令行中运行“Art list --pool=prototype | grep tg”(输出命令示例:http: //i.imgur.com/wyb57uB.png

  2. 从输出中查找第一行,其第三列是“AutoTestd@atest”或“”,并且在字符 ']' 之后没有单词(例如,示例中以 tg106 开头的行)

  3. 如果存在,运行“Art grab --pool=prototype tg106”(使用找到的行的前 5 个字符)

  4. 如果不存在,请等待 5 秒并返回到 1。

这是我目前拥有的:

#!/bin/bash

echo "Hello World!"
grabbed=false
while !grabbed do
   for /f "tokens=1,5,9" %%i in ('Art list --pool=prototype | grep tg') do
      if ("%%j" == "AutoTestd@atest" || "%%j" == "<free>") then
         echo "found"
         # grab a DUT
         Art grab --pool=prototype %%i
         grabbed=true;
      else
         echo "trying again..."
      fi
   done
   sleep 5
done

但是,尝试运行它时出现以下错误:

~@bs340.sjc> ./my_script

你好世界!

./my_script:第 6 行:意外标记 `"tokens=1,5,9"' 附近的语法错误

./my_script: line 6: ` for /f "tokens=1,5,9" %%i in ('Art list --pool=prototype | grep tg') do'

4

1 回答 1

2
# Until we find a line containg word1 or word2, and ending with a ]
until line=$(command1 | grep -E '(word1|word2).*]$' | head -n 1); [[ $line ]]
do
    # Sleep and try again
    sleep 5
done

#Run the final command with the first 5 chars from that line
command2 "${line:0:5}"
于 2013-06-21T23:20:05.917 回答