The way to watch the output of a command on a remote server using `watch` and `ssh`?

Published on Aug. 22, 2023, 12:20 p.m.

To watch the output of a command on a remote server using watch and ssh, you can use the following command:

watch -n <interval> ssh <user>@<remote_server> "<command>"

Replace <interval> with the desired update interval, <user> with the username on the remote server, <remote_server> with the hostname or IP address of the remote server, and <command> with the command you want to execute on the remote server.

For example, to watch the output of the top command on a remote server every 5 seconds, you can use this command:

watch -n 5 ssh [email protected] "top"

This will execute the top command on the remote server through SSH every 5 seconds, and display the output in the terminal.

Note that you will need to have SSH access to the remote server and have the necessary permissions to execute the command you’re watching. Also, make sure to use quotes around the command to ensure it’s executed correctly on the remote server.

Tags: