如何保存“手表"的输出?归档 [英] How to save output of "watch" to file

查看:83
本文介绍了如何保存“手表"的输出?归档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想每60秒运行一条命令,然后将输出保存到日志文件中. 我知道我可以通过以下方式打印到控制台

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?

推荐答案

Watch旨在在控制台窗口中运行.由于大量无法打印的格式字符,将其输出打印到文件很不方便.

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.

如果确切的60秒不是问题,则可以不加观察而尝试:

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.

这篇关于如何保存“手表"的输出?归档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆