在stdin上通过管道传输数据时,调用ausearch的脚本的行为有所不同 [英] Script that calls ausearch behaves differently when piped data on stdin

查看:123
本文介绍了在stdin上通过管道传输数据时,调用ausearch的脚本的行为有所不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释为什么通过STDIN传递bash脚本数据会导致脚本中的命令不能起作用吗?

Can someone explain why passing a bash script data via STDIN would cause the command within the script to NOT function?

脚本:

#!/bin/bash
ausearch -i -a 1221217

如果我运行以下命令,它将输出预期的ausearch结果:

If I run the following it outputs the ausearch results as expected:

./au.sh

但是,如果我这样做:

echo "blah" | ./au.sh

然后输出:

<no matches>

两个执行方法都应返回相同的结果(因为ausearch是硬编码的),但stdin似乎将其破坏了.

Both execution methods should return the same results(since ausearch is hardcoded) but stdin seems to break it.

询问如何在bash脚本中读取stdin数据.

I am NOT asking about how to read stdin data in a bash script.

推荐答案

ausearch如果stdin是管道,则更改其行为.如果是,它将通过标准输入而不是通过审计守护程序日志进行搜索.您可以使用--input-logs强制其从日志中读取.

ausearch changes its behavior if stdin is a pipe. If it is it searches through stdin rather than through the audit daemon logs. You can use --input-logs to force it to read from the logs.

echo "blah" | ausearch -i -a 1221217 --input-logs

重定向stdin将达到相同的目的.

Redirecting stdin would achieve the same end.

#!/bin/bash
ausearch -i -a 1221217 < /dev/null

这篇关于在stdin上通过管道传输数据时,调用ausearch的脚本的行为有所不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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