Questions tagged [watch]

watch will execute a program periodically, displaying the output.

Filter by
Sorted by
Tagged with
0 votes
2 answers
26 views

Kubuntu: how to disable color in output of 'watch' command

I am runnung Kubuntu 20.04. Command watch is from package procps. dpkg -l procps shows the version: 2:3.3.16-1ubuntu2 I am redirecting the output of warch to a file, like watch -t "date" &...
user avatar
1 vote
2 answers
56 views

Why doesn't watch bash -c '"echo $RANDOM"' print anything?

I expect this command to print a random value to the screen every 2 seconds, but instead it doesn't print anything: watch bash -c '"echo $RANDOM"' This command, however, does print a random ...
user avatar
  • 159
3 votes
1 answer
66 views

How to tackle leaking file watchers on Debian 11?

I work with a couple different nodejs live servers as part of my job and there seems to be some kind of leak within my tooling/workflow causing file watchers to accumulate over time until they hit the ...
user avatar
  • 177
0 votes
0 answers
20 views

How can I best track agrs in the environment without using ps?

I am working with a customer BusyBox v1.23.2 container, trying to track args being passed in the environment. I wanted to use pslogger to show when foo is sent in the environment. However, the ps tool ...
user avatar
1 vote
2 answers
96 views

Scrollable version of `watch`

We need to track a status file that is rewritten every few seconds by a server process. The watch command works beautifully for this (i.e. watch cat file.txt), except now the table is several pages ...
user avatar
1 vote
2 answers
128 views

watch command displays different ps results than when running script by itself

Here's my script: $ cat count_tomcat.sh ps -ef | grep tomcat| wc -l $ ./count_tomcat.sh 2 Now with the watch command it has different results: $ watch ./count_tomcat.sh Every 2.0s: ./count_tomcat....
user avatar
  • 1,313
0 votes
2 answers
16 views

`watch` a PostgreSQL query without displaying the full connection string

I'd like to share online, with team members, some live modifications on a PostgreSQL database (hosted on a dockerized Debian Bullseye) using watch (if you know any other tool, preferably pgAdmin4 but ...
user avatar
  • 213
0 votes
1 answer
22 views

Get updated output when using watch

I use watch to monitor the progress of file conversions. watch -n 2 "echo Converted: $(ls *.mp3 | wc -l) of $(ls *.wav | wc -l) files" When using command substitutions using the $(command) ...
user avatar
  • 125
1 vote
2 answers
62 views

I cant wrap command inside watch

I have got this perfectly working command: netstat -tuplean | awk '{NR>1; if( $6 ~ /ESTABLISHED/ ) print "\033[0;31m" $5 " \033[01;31m"$6;if ($6 ~ /_WAIT/ ) print "\033[...
user avatar
  • 69
9 votes
2 answers
520 views

ls formatting inside watch command

When I do ls /dev/tty*, I see the following output: /dev/tty /dev/tty12 /dev/tty17 /dev/tty21 /dev/tty26 /dev/tty30 /dev/tty35 /dev/tty4 /dev/tty44 /dev/tty49 /dev/tty53 /dev/tty58 /dev/...
user avatar
  • 605
0 votes
2 answers
241 views

How to make backgrounded `watch` execute command on change

I wanna use watch on certain commands and files (e.g. w), having it run in the background and notify me of any change. I've tried the following: (watch -g cat tmp && echo "changed") &...
user avatar
0 votes
2 answers
437 views

How to watch a for-loop in bash?

Is it possible to use a for-loop with the watch command? I'm not really sure what to make of this error with what I've tried: $ for i in 1 2 3; do echo $i; done 1 2 3 $ watch -n 10 for i in 1 2 3; do ...
user avatar
  • 1,291
0 votes
1 answer
59 views

Shell script error ONLY when using watch command

I'm trying to create a shell script that reads and writes to certain text files on two second intervals. When I run the script by itself (without watch), it works perfectly fine. However, when I run ...
user avatar
2 votes
1 answer
61 views

Observe command until output remains the same. Inverse of `watch -g`

Is there a possibility to watch a command until the output remains the same? With watch -g, one can check if a commands results changed and use this as a trigger to go to the next step in a script. ...
user avatar
  • 10.6k
1 vote
1 answer
48 views

Bright colors do not display in watch --color

Given the following python script to print colored text: for i in range(30, 100): print(f'\033[{i}m{i}\033[0m', end=' ') print() Running on bash displays bright ...
user avatar
1 vote
1 answer
272 views

How to `watch` output of `xxd` or `hexdump` command?

My tool is wtiting binary chars to stdout and I can view it in hex with # ./md /dev/ttyUSB0 | xxd 0000000: 6f03 1100 0003 0084 8400 0000 0900 0a00 o............... 0000010: 0008 0004 0000 0000 2c00 ...
user avatar
  • 2,517
4 votes
1 answer
1k views

How to use aliases with `watch` command?

I have some bash aliases in my ~/.bashrc, but they're not available within a watch command. Normally, I would source ./some_script.sh which uses these aliases, but am having trouble figuring out how ...
user avatar
  • 3,646
0 votes
1 answer
881 views

watch tail -20 ls -ltr?

I would like to see the latest content of a directory. I tried watch tail -20 ls -ltr ./{directory} it is not working. Is there a way to constantly shows the content of a directory like watch command?
user avatar
  • 121
0 votes
2 answers
97 views

watch without blank line

I want to execute a program periodically and watch when something changes. It sounds like watch would be the right command for that but it prints out annoying empty lines which makes it impossible to ...
user avatar
1 vote
0 answers
173 views

Have watch exit, when the output does not change anymore

Is there a simple way to have watch cancel, if the output does NOT change anymore? watch -g will exit once the output changes, but I want the opposite. So watch the output as long as it is still ...
user avatar
  • 11
9 votes
1 answer
218 views

Why does watch not show anything on screen when invoked with timeout in an script?

When I run this script, it does not display the watch output on the screen, and does not timeout after 5s. § cat script.sh #!/bin/bash timeout 5s watch -n 1 ps This is what I see on the screen when I ...
user avatar
0 votes
1 answer
92 views

how to repeatedly stop and restart a command

I'm trying to find a simple way to repeatedly restart a command after a certain time (let's say 10 seconds for the purpose of this question). For simplicity let's say the command in question is htop -...
user avatar
  • 103
1 vote
1 answer
475 views

Write only differences with watch -d command

I have to use watch in order to write in a file (doc.txt) the differences between a new version of a file and an older. I tried watch -t -d -n 10 "cat myfile.txt | tee doc.txt" but all myfile.txt's ...
user avatar
  • 11
3 votes
1 answer
1k views

What is this : ^[3;J^[H^[2J?

I am on a Debian system fresh installed, logged in via ssh on /dev/pts/0, and have entered the following command watch -n 10 clear > /dev/pts/0 ; netstat -tupn 2>/dev/null | grep -v 3306 > /...
user avatar
0 votes
1 answer
43 views

Bug: `watch &` won't work within a script

I had the following script to alert me when someone sends me mail: cd /var/mail watch -g ls && cat end ./alert end would be a blank file; when I am going home, I would modify the end file ...
user avatar
  • 1,029
0 votes
0 answers
137 views

du displaying strange file size, seems to follow some awkward size count rule

I'm facing something I can't explain to myself on a CentOS 7 VM. I'm watching a log file which is growing at a ~100KBps rate. I have a watch calling du but the output is always a power of 2, like in ...
user avatar
  • 123
-2 votes
1 answer
308 views

Watch command linux

when executing watch command to check a bunch of errors, the window is not able to show the rest of the errors when it reaches a certain amount of rows. I want to be able to see all rows being ...
user avatar
0 votes
0 answers
38 views

How to prevent tabulated outputs of functons being messed up when using 'watch' over ssh?

While ssh-ing into my server I want to be able to monitor for activity over certain port using netstat. Instead of running it manually I want to automate it with watch. While the command (sudo netstat ...
user avatar
  • 103
0 votes
1 answer
35 views

watch to remember its last zero exit output

I run a process that takes lot of time. Time is not a problem actually but I would like to know how much RAM memory it requires. Process is already running so /usr/bin/time is not an option. I found ...
user avatar
0 votes
2 answers
122 views

How to invert 'watch -b'?

I'm trying to get my terminal to alert me with a simple bell once my domain registration has finished (is resolvable). From watch --help: Options: -b, --beep beep if command has a ...
user avatar
  • 5,340
8 votes
3 answers
1k views

How can I watch the 17th (or last, if less) line in files of a folder?

I'm currently using watch head -n 17 * which works, but also shows all lines up to the 17th. Basically, I would like to only show the last line for each file that is shown with my current approach. ...
user avatar
9 votes
1 answer
708 views

Explain why watch 'jobs' does not work but watch 'ps' work?

jobs is my favorite command to see my codes which are running in the background. In order to check for them dynamically, I tend to type watch 'jobs' which does not display anything. However watch '...
user avatar
  • 257
0 votes
2 answers
683 views

Does the "watch" command put stress on a scheduler?

I have an account on a compute cluster which uses the SLURM scheduler. I have some jobs in the queue and I'm using the "watch" command to see their status: watch squeue -u myUserName Does constantly ...
user avatar
0 votes
1 answer
335 views

How to monitor if a binary has been executed with no additional tool?

I want to be able to tell if a certain executable is called on a ubunutu machine. The binary is to be called by a java process. I have no permission to install additional software. Here is what I ...
user avatar
0 votes
1 answer
71 views

output of watch several commands not clear

I am restoring a database backup on my server and i need to watch output of df -h and restore utility db2pd -utilities. I tried this: watch -n 2 "db2pd -utilities && df -h output(summarized): ...
user avatar
6 votes
1 answer
20k views

How can I use the watch command to run a bash script and monitor output file? [closed]

So I have a bash script "example.sh" that will write into an output file, say "tmp_output.txt". (It will empty the file and rewrite if data already exists in it) How can I use the watch command so ...
user avatar
  • 61
2 votes
1 answer
590 views

A tool for monitoring progress and ETA of an arbitrary process

I'm looking for a tool that takes two arguments: a command to execute, and a target value The tool should then run the command continuously, look for a number in the output of the command, and ...
user avatar
  • 362
0 votes
1 answer
879 views

Pipe file containing list of images to sxiv and reflect changes immediadly

Suppose I have a file images.txt which contains for example image1.jpg image2.jpg image3.jpg Then I pipe the images.txt to sxiv and I want that the thumbnail view reflects the changes immediately. ...
user avatar
  • 16.7k
1 vote
2 answers
1k views

Can you force the SSH "watch" command to append the output instead of overwrite?

I'm attempting to watch my network statistics via putty and want to write the statistics to a log file every one second. I've configured putty to log he ssh session to a log file. However, I'm ...
user avatar
  • 587
0 votes
1 answer
632 views

Use command output as argument in watch command

I have a watch on jq -r '.' $(ls -t | head -1)" The goal is to apply "jq -r '.'" to the most recently modified file in directory. Unfortunately, the command used to know the last modified file is ...
user avatar
2 votes
4 answers
1k views

Define function in fish, use it with watch

I want to define a function, and call that function every n seconds. As an example: function h echo hello end Calling h works: david@f5 ~> h hello But when using watch, it doesn't... watch ...
user avatar
3 votes
1 answer
314 views

tree(1) colours not properly interpeted by watch(1) even with --color option

I am using a simple combination of commands to "monitor" a bit of my filesystem change: watch and tree. Except I want colours and can't get it. Here's what I thought should work: watch --color 'tree -...
user avatar
  • 33
4 votes
2 answers
1k views

`watch` command with piping `|` [duplicate]

I want to keep monitoring a specific job on a slurm worload like cluster. I tried to use the watch command and grep the specific id. If the job id is4138, I tried $> watch squeue -u mnyber004 | ...
user avatar
  • 257
3 votes
1 answer
466 views

Interrupting watch if command execution was successful

I would like to be able to interrupt watch if execution of command was successful. In effect, I'm looking for a reverse behaviour than that offered via --errexit. As per man: -e, --errexit ...
user avatar
  • 273
5 votes
1 answer
8k views

Using watch or alternative to watch multiple commands at once

While running data-heavy scripts that take a long time to run, I like to use these commands to monitor the status/progress of the script. I can then leave the constantly-updating output open as sort ...
user avatar
  • 53
2 votes
0 answers
1k views

How can a systemd user service run the xclip command?

I'd like to automatically clear the clipboard a few seconds after use. #!/usr/bin/env bash LOCKFILE=/tmp/.clearclip-lock if [ -e ${LOCKFILE} ] && kill -0 `cat ${LOCKFILE}`; then exit 1 fi ...
user avatar
  • 247
2 votes
1 answer
1k views

Watch-command-alias-expansion AND need to use quotes

My questions is similar to the watch question here but with a twist. I need to use quotes, which seem to be stripped by an aliased watch. I want run watch on a custom slurm squeue command: $alias ...
user avatar
3 votes
2 answers
680 views

how to perform a calculation on the output of cat and then format it [closed]

I don't know shell scripting at all, but I have this cat /sys/class/power_supply/BAT0/power_now which gives me the output in milliwatts, which i would like to format as watts and use in watch watch ...
user avatar
  • 143
1 vote
1 answer
4k views

How to interrupt the watch command?

I have a program which prints some info to stdout and I run it like so: watch -n 0.1 myprogram My problem is that I need myprogram to exit cleanly, calling appropriate destructors to release system-...
user avatar
  • 8,649
0 votes
0 answers
66 views

Can the watch command be used as a hook?

Is it possible to use the watch command (in a pinch...ie without installing other software on Redhat) with ls to monitor a directory for files created so that when they are created a command can be ...
user avatar
  • 4,039