Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [watch]

watch will execute a program periodically, displaying the output.

0
votes
2answers
47 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 ...
0
votes
1answer
21 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 ...
0
votes
3answers
80 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 ...
1
vote
1answer
31 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 -...
2
votes
2answers
224 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 | ...
2
votes
1answer
26 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 ...
1
vote
1answer
132 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 ...
1
vote
0answers
116 views

trying to clear the clipboard

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 ...
2
votes
1answer
74 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 ...
3
votes
2answers
60 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 ...
1
vote
1answer
441 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-...
0
votes
0answers
46 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 ...
1
vote
1answer
558 views

Watch command with ls and shell globs

I tried running the command watch -n1 ls foo/bar* which I want to list files matching foo/bar* every second. However, what actually happens is that the shell expands the glob and what watch runs is, ...
2
votes
1answer
132 views

Bash (sed) script works directly from command line but not through watch

I have the following script to monitor some running processes: $ cat ./print_running.sh #!/bin/bash ps aux | grep 'python energydata.py' | sed -r 's/\{"spectral": 0//;s/, "pp_enable.*y": 0.9,//;s/ "...
1
vote
1answer
50 views

Creating a 'sub-screen', similar to how watch behaves [duplicate]

I have a Python script which generates a lot of different text outputs that require me to clear the screen quite regularly. The problem with this is that once the script is finished, I have a terminal ...
0
votes
3answers
127 views

Make watch reevaluate command

Hi I have a problem running watch command like this: watch cat /proc/$(ps ax | grep processname | grep -v grep | awk '{print $1}')/status The command works when I start it. However, then I restart ...
2
votes
2answers
2k views

How can I run a particular script every second?

I have tried using crontab, but it is limited to minutes. Is there any other option? I have also tried something like: watch -n 1 sh /path-to-script/try.sh But whenever I close the terminal it ...
0
votes
1answer
132 views

why does watch remove the colors from git log

possible duplicate : watch command not showing colors for 'git status' running the following command: watch -n1 git --no-pager log --oneline --graph -20 reproduces what i expect only it strips ...
1
vote
2answers
2k views

Stop watching the output of a particular program after using watch command?

I have come to know that we can use watch command to monitor the output of other command and it prints the output every 2 seconds by default, which is really useful. I start to use it to monitor the ...
3
votes
1answer
44 views

How to periodically watch a file from a list of files

I've a running java project that prints it's output to a file named in according to the current time: 03:45 ==> 03.out 13:24 ==> 13.out etc... Now I want to watch tail of the file currently ...
26
votes
6answers
4k views

How to run ssh command until succeeded?

Sometimes I restart a device and need to ssh back in when it's ready. I want to run the ssh command every 5 seconds until the command succeeds. My first attempt: watch -n5 ssh me@device.local &&...
0
votes
2answers
120 views

What happens in “watch” when the called command has not yet finished?

A server produces large amounts of data which I'd like to download as continuosly as possible. The simplest idea is to just use watch rsync ... As far as I understand, watch will call rsync every 2 ...
0
votes
1answer
263 views

How to open a new terminal window running watch process

I have a menu with an option to watch the contents of a folder every 15 seconds. I know I can watch this folder by using watch -n 15 ls -l, but I need to have this watch process open up in a fresh ...
3
votes
1answer
4k views

Working solution for ``watch ps aux | grep foo`` [closed]

watch ps aux | grep foo is not working: bash: syntax error near unexpected token `}' How can I fix this or is there even a better way?
3
votes
1answer
109 views

Colorize output from sensors

I use sensors to keep an eye on CPU temperatures on the console. This is part of the output: coretemp-isa-0001 Adapter: ISA adapter Physical id 1: +45.0°C (high = +80.0°C, crit = +90.0°C) Core 0: ...
0
votes
2answers
958 views

Is there a way to 'tail -f' a folder? [duplicate]

I need a command that acts like tail -f (displays file changes in realtime), but it should display the new output for all files (even if the new file is created/added). I don't know what files will be ...
0
votes
1answer
393 views

Perform periodic task using BASH and watch command

I'm trying to write a BASH script with the purpose of using watch command to monitor a local git repository for changes from the remote branch and then executing a task. Let's say the script is ...
1
vote
2answers
107 views

Showing list of files in current directory while navigating? (Screen, Linux)

I'm looking for a way to have list of all files/folders of the current directory in my terminal that updates automatically and runs while I'm actively navigating and editing files. I imagine it to ...
0
votes
4answers
96 views

How to repeatedly alternate between two (or more) commands?

I'd like to repeatedly iterate over, alternate between, and/or cycle through multiple commands; in a kind of pattern or loop. The desired end result could be thought of as not totally unlike watch. I'...
3
votes
1answer
526 views

Colored grep output getting fragmented by watch command

I'm trying to run watch, so that it shows me the output from my grep command, while I am running over files and changing things. The usual way of doing this works fine, but lacks colors: watch grep '...
0
votes
3answers
675 views

Break infinite 'while' loop on FreeBSD

I have a barebones FreeBSD system with only a terminal. I would like to monitor zpool status every 15 seconds or so. Usually on "regular" systems I would use watch -n15 but this is not available here. ...
1
vote
2answers
63 views

How to watch a large file for changes that can occur anywhere?

I'd like to watch a file for changes that might occur. Normally, using tail -f file or watch -d cat file would be fine for this. However, the file I am monitoring is too large to fit on one screen, ...
1
vote
2answers
299 views

How to create a debian/watch file? [closed]

Debian has a file called watch file which is used for keeping track of new releases. I tried to create a watch file to see how it works from the Debian wiki and tried to copy the same for a game ...
0
votes
0answers
28 views

How to run script periodically through watch on remote host? [duplicate]

I would like to run a background script periodically on a remote host via ssh. I create a script that run another script in background on the remote host like that: nohup watch -n5 ./script.sh &...
22
votes
2answers
11k views

How to use watch command with a piped chain of commands/programs

I usually user watch linux utility to watch the output of a command repeatedly every n seconds, like in watch df -h /some_volume/ But I seem not to be able to use watch with a piped series of command ...
1
vote
1answer
624 views

what is the right syntax for watch command

I want to follow the word BLOCK in ufw.log file every two seconds I try this command: sudo watch BLOCK /var/log/ufw.log but I getting: sh: 1: BLOCK: not found what is the right command? Thank ...
0
votes
1answer
2k views

is it possible to monitor the /var/log/secure or /var/log/message using watch command

When I was trying to monitor the /var/log/secure or /var/log/message using watch command the output showed as /var/log/messages: Permission denied. Is it possible to monitor the /var/log/messages and /...
0
votes
1answer
3k views

How to stop a “watch” process

I use "Pleeease" to watch CSS files and automatically compile them when any change happens. I did pleeease watch and then just close the terminal, the wathcing process keeps running. Now I want to ...
1
vote
1answer
4k views

How to start a command every 5 seconds on Solaris?

How to start a command for example ls -la every 5 seconds on Solaris ? . I'm searching for something like watch -n 5 ls -la
2
votes
2answers
2k views

Color output of linux command similar to 'watch -d' to highlight differences?

I'm at the beginning of shell scripting etc. and a bit challenged to find the proper way of colorzing a command's repeating output, similar to the -d option in the watch command. I want to see the ...
13
votes
2answers
704 views

Why does `watch` make `ls /tmp` list contents of $HOME?

I'm trying to watch number of files in my /tmp/ directory. For this I thought this command would work: watch sh -c 'ls /tmp/|wc -l' But it appears to work as if ls had no arguments. Namely, I'm in ~,...
3
votes
4answers
67 views

Is there a variant of watch that only refreshes upon receiving a signal?

I have a window that runs a somewhat expensive watch git log ... incantation — expensive enough that it actually looks more like watch -n30 timeout 10 git log ... so that it doesn't excessively ...
0
votes
1answer
507 views

Pretty print output of “kill -USR1”-ing dd

When dd is done it prints a three line summary about the number of read and written segments, the total size and average writing speed. While it does its work, dd is awfully quiet. Not too long ago (...
0
votes
1answer
309 views

Linux `watch` segmentation fault

When I try to use Linux watch with a command which returns color output, I get the error: segmentation fault (core dumped). The command itself is the following: watch --color --no-title --interval 1 ...
3
votes
1answer
354 views

Watch not showing subshell output

Why does the following not output "hello" line? watch bash -c 'echo hello' As this one? watch 'echo hello' I expected to have echo write to bash output directly and this to be read by watch and ...
1
vote
2answers
185 views

Watch: Only print to screen if output has changed since last output

I'm running a process and I'm counting the number of threads with ps huH p <PID_OF_U_PROCESS> | wc -l I can run this thread with watch like this; watch -n 1 ps huH p <PID_OF_U_PROCESS> |...
0
votes
2answers
426 views

watch not displaying output of script

I have a simple script which just uses awk to extract some information from output of ps. When I run this on the terminal, it works fine. But, when I run this script with watch: watch bench_run.sh ...
7
votes
2answers
4k views

How to wrap output of watch command?

Consider the following command: watch -d "ps -ef | grep java" It gives following output: kshitiz 11369 11285 0 Oct13 ? 00:06:02 /usr/lib/jvm/jdk1.7.0_40/jre/bin/java -Djava.awt.headless=...
9
votes
3answers
3k views

Perform command every X seconds

I wish to perform a command ever 10 seconds, and have it executed in the background (thereby eliminating watch?). All the answers show something like the following, but this will execute ever 11 to ...
2
votes
1answer
2k views

Run multiple commands in watch

I have a small script, that I want to constantly run until I Ctrl+C. I saw a few suggestions of using watch, and the small examples I've seen work fine, but I can't get it to work for me. Here's my ...