Find the answer to your Linux question:
Results 1 to 3 of 3
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: Code: ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2010
    Posts
    2

    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:
    Code:
    mSergani:~ $ ssh user.at.192.168.1.100 "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.

    Thanks.

    //M

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    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:
    Code:
    #!/bin/sh
    while :; do
      ssh "df -h"
      sleep 2
    done

  3. #3
    Just Joined!
    Join Date
    Feb 2010
    Posts
    2
    I was able to do the task with the -t option
    Code:
    mSergani:~ $ ssh -t user.at.192.168.1.100 "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
    $spacer_close

Posting Permissions

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