I want to run a command every 60 seconds, and save the output to a logfile. I know I can print to console by
watch -n 60 <mycommand>
But what if I want to save it to a file as well as print to console?
I want to run a command every 60 seconds, and save the output to a logfile. I know I can print to console by
watch -n 60 <mycommand>
But what if I want to save it to a file as well as print to console?
try it:
I use
tee
so that you can see the output on your terminal as well as capture it in your log.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:
This saves the output to a log file and shows it on console as well.