How to Save Output of "Watch" to File

How to save output of watch to file

Watch is designed to run in a console window. Printing its output to file is inconvenient, because of the extensive amount of unprintable formatting characters.

You can try this without watch, if the exact 60 seconds is not an issue:

 while <some condition>
do
<mycommand> 2>&1 | tee -a /path/to/logfile
sleep 60
done

This saves the output to a log file and shows it on console as well.

Watch file output in bash terminal as it is being written to the file

Use the command tee - from it's man page,

Synopsis

  tee [OPTION]... [FILE]...

Description

  Copy standard input to each FILE, and also to standard output.

Or, you could run tail -f on the written file to watch as it is being written (-f is follow).

How to record watch command output to a file in gdb

I have to press c to continue debugging.

Note that pressing <Enter> will repeat previous command (e.g. previous c).

Is there any way to instead of hitting enter for endless time, I just ask gdb to save all the changes in the register to a file?

Sure:

(gdb) watch $rax
Watchpoint 2: $rax

(gdb) commands 2
Type commands for breakpoint(s) 2, one per line.
End with a line saying just "end".
>c
>end

# This is to prevent stop after every screen-full of output
(gdb) set height 0

(gdb) set logging on
Copying output to gdb.txt.

(gdb) continue

Voila: you now have all the changes in gdb.txt

How to log to file inside brackground watch command?

Why would you use watch for this? It's intended to be interactive. Use while sleep loop:

while true; do
echo '`date +"%d-%m-%Y %H:%M:%S.%3N"` `/opt/vc/bin/vcgencmd measure_temp`';
sleep 1;
done >> temp.log' &

Doesn't exactly simulate what you'd get from watch. You could do that more or less with this if you really wanted:

while true; do
echo '`date +"%d-%m-%Y %H:%M:%S.%3N"` `/opt/vc/bin/vcgencmd measure_temp`';
sleep 1;
done | head > temp.log' &

Saving values of debug session from watch window to a file

Does it have to be a one-click export? You can select all, copy and paste into your output file. You can do it from Watch window, but the output is a bit more clear from either Immediate or Command windows.

You can beautify the format by creating a custom visualizer in C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Packages\Debugger\Visualizers (use your version of the VS).

Here is how it may look, for example:

<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="A">
<DisplayString>({e}:{x},{y},{z})</DisplayString>
</Type>
</AutoVisualizer>

unable to capture top command output in a file using watch command

Managed to write the output of top in a file and add it in cron so that i can get the output in a file after every time interval>>

script:

!/bin/bash

top -b -n 5 -u mysql >> top.txt

crontab entry:

*/1 * * * * cd /scriptpath && sh script.sh

sample output:

top - 17:31:01 up 5 days, 5:59, 3 users, load average: 0.42, 0.38, 0.40
Tasks: 193 total, 1 running, 190 sleeping, 1 stopped, 1 zombie
Cpu(s): 19.6%us, 0.6%sy, 0.0%ni, 78.9%id, 0.3%wa, 0.1%hi, 0.5%si, 0.0%st
Mem: 24686168k total, 24549032k used, 137136k free, 663424k buffers
Swap: 12289716k total, 140k used, 12289576k free, 19292760k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3259 mysql 15 0 3967m 3.5g 6372 S 52.9 14.9 3382:39 mysqld

top - 17:31:04 up 5 days, 5:59, 3 users, load average: 0.47, 0.39, 0.41
Tasks: 192 total, 1 running, 189 sleeping, 1 stopped, 1 zombie
Cpu(s): 4.5%us, 2.5%sy, 0.0%ni, 89.7%id, 0.0%wa, 0.6%hi, 2.8%si, 0.0%st
Mem: 24686168k total, 24549520k used, 136648k free, 663424k buffers
Swap: 12289716k total, 140k used, 12289576k free, 19292772k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3259 mysql 15 0 3967m 3.5g 6372 S 64.1 14.9 3382:41 mysqld

top - 17:31:07 up 5 days, 5:59, 3 users, load average: 0.47, 0.39, 0.41
Tasks: 192 total, 1 running, 189 sleeping, 1 stopped, 1 zombie
Cpu(s): 4.0%us, 1.8%sy, 0.0%ni, 91.7%id, 0.0%wa, 0.5%hi, 2.0%si, 0.0%st
Mem: 24686168k total, 24549256k used, 136912k free, 663428k buffers
Swap: 12289716k total, 140k used, 12289576k free, 19292772k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3259 mysql 15 0 3967m 3.5g 6372 S 56.1 14.9 3382:43 mysqld

top - 17:31:10 up 5 days, 5:59, 3 users, load average: 0.43, 0.39, 0.40
Tasks: 192 total, 1 running, 189 sleeping, 1 stopped, 1 zombie
Cpu(s): 4.0%us, 2.3%sy, 0.0%ni, 90.7%id, 0.0%wa, 0.5%hi, 2.5%si, 0.0%st
Mem: 24686168k total, 24549876k used, 136292k free, 663428k buffers
Swap: 12289716k total, 140k used, 12289576k free, 19292772k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3259 mysql 15 0 3967m 3.5g 6372 S 56.8 14.9 3382:44 mysqld

top - 17:31:13 up 5 days, 5:59, 3 users, load average: 0.40, 0.38, 0.40
Tasks: 192 total, 1 running, 189 sleeping, 1 stopped, 1 zombie
Cpu(s): 4.0%us, 2.1%sy, 0.0%ni, 91.2%id, 0.0%wa, 0.5%hi, 2.2%si, 0.0%st
Mem: 24686168k total, 24549876k used, 136292k free, 663436k buffers
Swap: 12289716k total, 140k used, 12289576k free, 19292772k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3259 mysql 15 0 3967m 3.5g 6372 S 54.8 14.9 3382:46 mysqld

Output a watched Visual Studio variable to a file

One way to do it would be to use the immediate window (menu Debug -> Windows -> Immediate). In the window that appears you can use the "?" to query the value of a variable.

Assuming your history variable is a string you view its contents by typing the following in the immediate window:

?history

You could copy and paste the output from there into a text file or alternatively ask Visual Studio to log all command window output. To do this type:

>log "c:\test.log"
>? history
>log off

Log is an alias for Tools.LogCommandWindowOutput and accepts the following parameters:

Tools.LogCommandWindowOutput [filename] [/on|/off] [/overwrite]

Check out the MSDN article Log Command Window Output Command for more information.
 



Related Topics



Leave a reply



Submit