Bash 脚本。在输出到文件的脚本中隐藏某个特定命令的输出

发布于 2024-12-17 08:35:34 字数 490 浏览 0 评论 0原文

我的这个脚本正在慢慢变大。它的输出通过管道传输到调用时的文件(稍后用于构建电子邮件正文),但是,我有一个在该脚本中调用的特定命令,我想削减其输出。

我试图

./somecommand | egrep "pattern1|pattern2"

在常规控制台窗口中执行 Which Works Fine 操作,但是当潜入我的较大脚本时,到egrep 的管道会被忽略,并且“./somecommand”的整个输出会落在父脚本的输出中。

怎样才能修复呢?

我将这个问题保持模糊以避免复制粘贴整个该死的事情。可根据要求提供更多信息。是的,脚本中的脚本中的脚本,我们需要更深入,等等。到目前为止,我最多有五个脚本处理不同的任务,作为更大的多服务器备份操作的一部分。主要操作脚本输出到一个文本文件,围绕该文件构建电子邮件正文,这用作最终用户看到的日志记录。我从主脚本中调用的一个特定脚本非常“嘈杂”,因此egrep仅获取与用户相关的输出。

谢谢各位!

This script of mine is slowly getting larger. It has its output piped to a file on invocation (which is later used to build an email body), however, I have one particular command that's invoked in that script whose output I want to trim down.

I was trying to do

./somecommand | egrep "pattern1|pattern2"

Which works fine in a regular console window, however when snuck into my larger script, the pipe to egrep gets ignored and the whole output of the "./somecommand" lands in the output of the parent script.

How can fix?

I'm keeping this question vague to avoid copy pasting the whole damn thing. More info can be provided on request. And yes, scripts within scripts within scripts, we need to go deeper, etc. I'm up to five scripts so-far handling different tasks as part of a larger multi-server backup operation. The main operating script is output to a text file which an email body is built around, this serves as the logging that the end user sees. One particular script I'm calling from within the main script is quite 'noisy', hence the egrep to grab just the output relevant to the users.

Thanks folks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

霞映澄塘 2024-12-24 08:35:34

是否有可能 ./somecommand 将其输出发送到 stderr 而不是 stdout?你可以尝试:

./somecommand 2>&1 | egrep "pattern1|pattern2"

Is it possible ./somecommand is sending its output to stderr instead of stdout? You could try:

./somecommand 2>&1 | egrep "pattern1|pattern2"
摇划花蜜的午后 2024-12-24 08:35:34

您尝试过 grep -v 选项吗?您是否获得某个命令文件中的所有脚本的单行输出?如果是这种情况,那么您可以使用 grep -v "pattern"

Did you try grep -v option? Do you get single line output for all the scripts that you have inside somecommand file? If thats the case then you could use grep -v "pattern"

月亮邮递员 2024-12-24 08:35:34

您可以尝试在调试模式下运行脚本,如下所示:

bash -x ./script

You may try to run your script in debug mode, like that :

bash -x ./script
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文