Questions tagged [watch]
watch will execute a program periodically, displaying the output.
132 questions
-4
votes
1
answer
83
views
Watch command but with shell
I want use shell and see watch on top parallel without switching to another tty.
Is theres way to do that?
-1
votes
1
answer
253
views
Watch command: Updates only periodically, not event-based? (Example: Every 2 seconds - every time file x gets saved)
What I'd like to have: Running a command y with watch command and have watch command update only as soon as output of command y has changed.
Imagine a bash script with 3 lines of echo output
Hello ...
-1
votes
2
answers
36
views
Linux "watch" command showing last 30 lines of nft list ruleset [duplicate]
I want to constantly see last 30 lines of code "nfc list ruleset" in Debian Bash. Something like this:
watch -n 1 nft list ruleset | tail -n 30
But above code doesn't show last 30 lines of &...
1
vote
1
answer
355
views
How can I get colored output of `systemd` commands run with `watch` inside xterm?
Somehow I'm unable to get this working with color output, it works but no colors are shown.
I'm currently using these alias'es in my bash shell:
alias Xterm='xterm -geometry 132x60 +dc +cm -e '
alias ...
-1
votes
1
answer
139
views
How can I 'sudo watch sensors' and 'sudo docker stats' in one window on Ubuntu Server?
I tried
watch 'sensors | sudo docker stats'
sudo 'docker stats | watch sensors'
sudo docker stats | sudo watch sensors
So I assume its not possible to display both outputs in one window? Other than ...
3
votes
1
answer
3k
views
How to run bash function in "watch" command?
Say I have a function f defined in my bashrc
function f() {
date
}
I want to run following command to monitor the output
watch f.
The command failed with "sh: f: command not found".
watch ...
1
vote
0
answers
32
views
Do I have to write a shell script purely to access bash for loops inside of say watch? [duplicate]
I'd like to monitor apps that have inotify instance in real-time with watch using something similar to:
watch "for foo in /proc/*/fd/*; do readlink -f $foo; done | grep inotify | sort | uniq -c | ...
1
vote
1
answer
93
views
`watch -n 100 'sh script.sh >> /path/to/output/output.txt` doesn't write to output.txt?
I'm currently executing the following:
watch -n 100 'sh script.sh >> /path/to/output/output.txt' &
It's been running for 30 minutes (I can verify with ps -ef | grep watch), however there's ...
2
votes
1
answer
196
views
alias for watch command gets stopped?
I create this alias, so that aliases get expanded in the watch statement.
> alias w='watch -x bash -i -c'
> alias k=kubectl
I execute it:
> w 'k get pods; echo; k get svc'
After two seconds ...
1
vote
0
answers
35
views
how to wrap command with many quotes into watch properly?
I have such a bash command ...
psql -c "SELECT datname FROM pg_database WHERE datname LIKE 'efa%' OR datname LIKE 'geocms%';"
and am wondering how to wrap this into watch -cd "<...
1
vote
1
answer
38
views
watch -n1 $() does not run $() every interval
watch -n1 $() does not update $().
what is the workaround?
here is my example:
watch -n1 echo $(( $(date +%s -d "sun") - $( date +%s ) ))
this results in
Every 1.0s: echo 106602 ...
0
votes
1
answer
631
views
terminal timer with end time given through bash
so I had the idea of making a bash function that takes in a time in hh:mm:ss (24 hour format) and makes a timer till that time
kinda like a one time alarm while also showing how much time is left
I ...
2
votes
0
answers
246
views
Watch command -d=cumulative gives unexpected behavior with --color
This script gives the expected behavior, highlighting the parts of the date that change:
watch -d=cumulative date
However this script highlights the entirety of the text instead of just the things ...
4
votes
2
answers
357
views
How can I see the change that caused watch -g to exit
I'm using watch -g to monitor the output of a command and exit as soon as it changes. The problem is that all the UI elements of watch (including the output of the command that I'm monitoring) ...
1
vote
0
answers
230
views
watch a whole directory and print diff on file change
Is there a way to easily watch a full directory for changes and print a diff when a file changed?
Context: I would like to discover the name of the options in KDE Plasma's configuration by watching ....
4
votes
1
answer
3k
views
Getting "Segmentation fault (core dumped)" every time I try to run `watch` with `nvidia-smi`
I'm currently using GPUs on an Ubuntu server to run machine learning models. I often like to use the watch command in order to monitor the GPU statuses like watch -n 1 nvidia-smi. It usually works ...
1
vote
1
answer
233
views
How to use alias to a watch command which include another alias and some double and single quotes in the latter alias?
alias vov="scontrol -o show nodes | grep -e \"-lkeb\" -e \"-gpu\"| awk '{ printf(\"%-15s%-9s%-7s%-18s%-11s%-9s%s\n\", substr(\$1, 10), substr(\$4, 10), substr(\$5, ...
0
votes
2
answers
167
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" &...
2
votes
2
answers
888
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 ...
5
votes
1
answer
643
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 ...
3
votes
3
answers
1k
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 ...
1
vote
2
answers
1k
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....
0
votes
2
answers
60
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 ...
0
votes
1
answer
239
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) ...
1
vote
2
answers
215
views
I can't wrap a command inside watch
I have 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[0;...
10
votes
2
answers
1k
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/...
1
vote
2
answers
2k
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") &...
1
vote
2
answers
3k
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 ...
0
votes
1
answer
617
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 ...
2
votes
1
answer
187
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. ...
1
vote
1
answer
613
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 ...
0
votes
1
answer
915
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 ...
7
votes
1
answer
3k
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 ...
0
votes
1
answer
6k
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?
0
votes
2
answers
371
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 ...
2
votes
0
answers
891
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 ...
8
votes
1
answer
702
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 ...
1
vote
1
answer
1k
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 -...
1
vote
1
answer
3k
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 ...
3
votes
1
answer
3k
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 > /...
0
votes
1
answer
175
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 ...
0
votes
0
answers
211
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 ...
-2
votes
1
answer
367
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 ...
0
votes
0
answers
85
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 ...
0
votes
1
answer
40
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 ...
1
vote
2
answers
350
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 ...
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. ...
9
votes
1
answer
834
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 '...
1
vote
2
answers
2k
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 ...
0
votes
1
answer
758
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 ...