What's a simple method to dump pipe input to a

2019-04-28 03:46发布

I'm looking for a little shell script that will take anything piped into it, and dump it to a file.. for email debugging purposes. Any ideas?

标签: linux pipe exim
11条回答
ら.Afraid
2楼-- · 2019-04-28 04:13

Use <<command>> | tee <<file>> for piping a command <<command>> into a file <<file>>.

This will also show the output.

查看更多
Deceive 欺骗
3楼-- · 2019-04-28 04:14

if you don't care about outputting the result

cat - > filename

or

cat > filename
查看更多
老娘就宠你
4楼-- · 2019-04-28 04:16

If you want to analyze it in the script:

while /bin/true; do
    read LINE
    echo $LINE > $OUTPUT
done

But you can simply use cat. If cat gets something on the stdin, it will echo it to the stdout, so you'll have to pipe it to cat >$OUTPUT. These will do the same. The second works for binary data also.

查看更多
Viruses.
5楼-- · 2019-04-28 04:23

If you want a shell script, try this:

#!/bin/sh
exec cat >/path/to/file
查看更多
smile是对你的礼貌
6楼-- · 2019-04-28 04:26

Huh? I guess, I don't get the question?

Can't you just end your pipe into a >> ~file

For example

echo "Foobar" >> /home/mo/dumpfile

will append Foobar to the dumpfile (and create dumpfile if necessary). No need for a shell script... Is that what you were looking for?

查看更多
登录 后发表回答