Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

watch

Run a command again every few seconds and show the output full screen — a live view of pods, disks or connections.

Niveau
DevOps-tool
Groep
Processen en jobs
Root nodig
Nee
Pakket
procps-ng

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

watch clears the screen and runs a command every 2 seconds (or the interval you choose). It is the quick way to follow a rollout, a disk that fills up, or a queue that empties, without writing a loop.

With -d it marks what changed since the last run. Put the command in quotes when it has pipes.

Zo schrijf je het

watch [OPTIONS] COMMAND

Opties 10

Meest gebruikt

Options

-n SECS, --interval
Run every SECS seconds (can be 0.5).
-d, --differences
Mark the changes between runs.
-d=permanent
Keep all changes marked since the start.
-g, --chgexit
Exit when the output changes.
-e, --errexit
Stop when the command fails.
-t, --no-title
Hide the header line.
-c, --color
Show the colours of the command.
-x, --exec
Run the command without sh -c (no shell parsing).
-p, --precise
Run at exact intervals.
-b, --beep
Beep when the command fails.

Voorbeelden 11

$ als gewone gebruiker# als root (of met sudo)

  1. 1Follow the pods during a rollout

    watch -n 1 kubectl get pods -o wide
  2. 2Mark what changes

    watch -d 'kubectl get deploy shop'
  3. 3A disk that fills up

    watch -n 5 'df -h / /var'
  4. 4Count open connections to port 443

    watch "ss -Htn state established '( sport = :443 )' | wc -l"
  5. 5Stop as soon as something changes

    watch -g 'kubectl get pod migrate-db -o jsonpath={.status.phase}' && echo "phase changed"
  6. 6Wait until a file appears

    watch -g ls /var/run/app.ready
  7. 7Keep the colours of the command

    watch -c 'git -c color.status=always status -s'
  8. 8A queue in RabbitMQ

    watch -n 2 'rabbitmqctl list_queues name messages'
  9. 9Memory every second, without the header

    watch -t -n 1 free -m
  10. 10Stop when the health check fails

    watch -e -n 10 'curl -fsS http://localhost:8080/health'
  11. 11Docker containers and their state

    watch 'docker ps --format "table {{.Names}}\t{{.Status}}"'

Let op

  • Quote the whole command when it has |, > or ;, or the pipe applies to watch itself.
  • Short intervals with heavy commands (big kubectl lists) add load to the API server.

Tips om te onthouden

  • kubectl get pods -w streams changes without watch; watch is better for a full table view.
  • Ctrl+C stops watch.

Exitcodes

0Normal exit.
1Bad options.
2Fork failed.
8-e and the command failed.