简体   繁体   English

我可以grep telnet命令输出吗?

[英]Can I grep telnet command output?

我有一个telnet命令打印数百行输出,我可以grep输出吗?

Use the 'script' command. 使用'script'命令。 If you run 'script ' before running telnet, all text that gets written to the terminal also gets written to /file/path/filename. 如果在运行telnet之前运行'script',则写入终端的所有文本也会写入/ file / path / filename。 You'll have to do 'exit' or Ctrl-D to actually write to the file or you can keep a check on the file. 您必须执行“退出”或Ctrl-D才能实际写入文件,或者您可以检查文件。

Finally grep on the file using filename | 最后使用filename | grep文件 grep "search text" grep“搜索文本”

/file/path/filename is the path where you want to store the output of telnet. / file / path / filename是要存储telnet输出的路径。

Using script command 使用脚本命令

script /tmp/myscript.txt

then all the commands you fire in terminal and the output will go in this file. 然后你在终端中触发的所有命令和输出都将进入该文件。 use ctrl + D when you are done, which will write to the file. 完成后使用ctrl + D,它将写入文件。

Do a grep on this file. 在这个文件上做一个grep。

cat /tmp/myscript.txt | grep "textToSearch"

Use tee command to redirect the content to file: 使用tee命令将内容重定向到文件:

telnet google.com 80 | tee outfile

Then grep the file 然后grep文件

To grep output from the network connection, you can use Bash shell instead of telnet , eg: 要从网络连接grep输出,您可以使用Bash shell而不是telnet ,例如:

exec {stream}<>/dev/tcp/example.com/80
printf "GET / HTTP/1.1\nHost: example.com\nConnection: close\n\n" >&${stream}
grep Example <&${stream}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM