如何在Bash中将netcat数据连接成一个字符串变量以用于发送电子邮件?

huangapple go评论63阅读模式
英文:

How to concatenate netcat data to form a string variable in Bash for email sending?

问题

现在 = ''
nc -lvp 12345 | $now=$now$1

./ForwardMail.sh $now
英文:

Concatenate a string in a pipe, while getting data over netcat

I want to collect data over netcat from a specific port. This data should be transferred to another script and should be send via email. I started a pipe with xargs, but got the problem that every single line is send on its own. Now I wanted to concenate a string over the time of the connection and hand this over to the email sending script, but somehow I can't get the string concatenated

now = ''
nc -lvp 12345 | $now=$now$1

./ForwardMail.sh $now

Could someone help me to concatenate the string?

答案1

得分: 1

对于一个Bash脚本来说,这完全是无意义的。

第一行

now = ''

调用一个名为now的程序,带有两个参数:=和一个空字符串。

你正在将nc的输出传输到一个(格式不正确的)赋值操作中。这毫无意义。顺便说一下:在=的左侧使用$now也不是一个好主意。

大多数这些错误都会被shellcheck标记出来。

根据你的描述,我得到的印象是你想要做的是:

netcat=$(nc -lvp 12345)
./ForwardMail.sh "$netcat $1"

但即使这样也似乎很奇怪。可能,下面的方式会更好一些:

netcat=$(nc -lvp 12345|ts)

当然,我们不知道ForwardMail.sh是什么样的,以及它如何处理不同的行作为参数。

英文:

For a bash script, this is completely nonsense.

The first line

now = ''

calls a program now with two arguments: = and an empty string.

You are piping the output of nc to a (badly formed) assignment. That makes no sense. By the way: using $now on the left side of the = is also a bad idea.

Most of these errors wil be flagged by shellcheck

From your description, I get the impression that you want to do:

netcat=$(nc -lvp 12345)
./ForwardMail.sh "$netcat $1"

But even that seems strange. Possibly,

netcat=$(nc -lvp 12345|ts)

would be a better idea.

Ofcourse, we've no idea what ForwardMail.sh looks like, and what it does with different lines as argument.

huangapple
  • 本文由 发表于 2023年5月28日 22:55:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76352083.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定