Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Using ssh command with watch

    Hi all,

    I've been trying to use both ssh and watch commands in the same line, but getting this error:
    Error opening terminal: unknown.
    I'm typing the following command:
    mSergani:~ $ ssh "watch df -h"
    Can anyone help shed some light if it's possible to use both commands?
    It's highly important in my line of work.



  2. #2
    The watch command is meant to run in a terminal indefinitely, but your ssh command will just log in, run the command, and exit the shell (terminal). If you truly want the df command to run indefinitely, you should look into screen, which will keep a dedicated terminal open for watch to use.

    Or, you could run your df command on the remote machine in an indefinite loop, and redirect (append or overwrite) the output to a file, which you could then ssh in and read.

    Or, you could do the loop on the client/ssh side: in an indefinite loop, you could ssh in and grab the output of df, then log out:
    while :; do
      ssh "df -h"
      sleep 2

  3. #3
    I was able to do the task with the -t option
    mSergani:~ $ ssh -t "watch df -h"
    Also your method will not help me that much, as I have scripts running on the remote server monitoring for logins, and would immediately dispatch an email for the whole team about the new connection.

    Thanks for the help though

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts