bash - führe cmd2 jedes Mal aus, wenn cmd1 stdout einen bestimmten String ergibt

bash - führe cmd2 jedes Mal aus, wenn cmd1 stdout einen bestimmten String ergibt

Ich versuche zu rennen

WID=`xdotool search "Inbox" | head -1`
xdotool windowactivate $WID
xdotool key Up

jedes Mal stdout von

$ CAMEL_DEBUG=all evolution

ergibt "Startleerlauf".

Ich habe mir dieses Skript ausgedacht, das tut, was ich will, aber nur einmal. Es tut es nicht jedes Mal, wenn „Starting Idle“ angezeigt wird, sondern nur einmal und stoppt dann. Ich kenne Bash nicht gut genug, um es zu zwingen, sich endlos zu wiederholen.

exec 3< <(CAMEL_DEBUG=all evolution)

while read line; do
   case "$line" in
   *"starting idle"*)
      echo "'$line' contains staring idle"

    WID=`xdotool search "Inbox" | head -1`
        xdotool windowactivate $WID
        xdotool key Up

      break
      ;;
   *)
      echo "'$line' does not contain starting idle."
      ;;
   esac
done <&3

exec 3<&-

Danke.

Antwort1

Der breakBefehl beendet die whileSchleife. Lassen Sie ihn fallen.

Antwort2

Sie könnten es mit etwas Komplexerem versuchen. Leiten Sie zunächst die Ausgabe evolutionin eine Datei um:

CAMEL_DEBUG=all evolution > tmpout

Erstellen Sie dann eine Endlosschleife while, die die Datei liest und reagiert, wenn eine Zeichenfolge gefunden wird:

#!/usr/bin/env bash
while true; do
    while read line; do
    case "$line" in
        *"starting idle"*)
        echo "'$line' contains staring idle"

        WID=`xdotool search "Inbox" | head -1`
        xdotool windowactivate $WID
        xdotool key Up

        break
        ;;
        *)
        echo "'$line' does not contain starting idle."
        ;;
    esac
    done < tmpout
done

verwandte Informationen