是否有方法/工具直接从我的Shell输出生成HTML文档(类似于doxygen所做的)甚至是保存的日志?如果没有什么可用,你们对于如何使用现有工具有任何创意吗?
我在想,在键入时,我可以添加某种标记或特殊字符,然后使用工具选择作为注释的开头,而输入的其余部分是CLI和输出。
示例:
ubuntu@nso-172-73:~$ # This is a comment
ubuntu@nso-172-73:~$ ping google.com
PING google.com (172.217.9.174) 56(84) bytes of data.
^C
--- google.com ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1008ms
ubuntu@nso-172-73:~$ # End of Comment
答案 0 :(得分:0)
这并不能完全回答您的问题,但希望可以为您提供一个开始。
bash
有一个script
命令。这是一个令人困惑的名字,是吗?基本上,script
是一个交互式终端记录器。由于没有whatis
条目,因此这是man
页面的开始:
$ man script | head -n 17 | sed '/^$/d'
SCRIPT(1) User Commands SCRIPT(1)
NAME
script - make typescript of terminal session
SYNOPSIS
script [options] [file]
DESCRIPTION
script makes a typescript of everything displayed on your terminal. It
is useful for students who need a hardcopy record of an interactive
session as proof of an assignment, as the typescript file can be
printed out later with lpr(1).
If the argument file is given, script saves the dialogue in this file.
If no filename is given, the dialogue is saved in the file typescript.
让我给你一个例子,然后我将向您展示此命令的详细信息,并给出如何使用此命令的想法。我正在Cygwin终端上运行它。
$ script
Script started, file is typescript
$ pwd
/home/me
$ # This is a comment
$ ping google.com
PING google.com (172.217.12.206): 56 data bytes
64 bytes from 172.217.12.206: icmp_seq=0 ttl=51 time=68 ms
64 bytes from 172.217.12.206: icmp_seq=1 ttl=51 time=67 ms
64 bytes from 172.217.12.206: icmp_seq=2 ttl=51 time=67 ms
64 bytes from 172.217.12.206: icmp_seq=3 ttl=51 time=67 ms
64 bytes from 172.217.12.206: icmp_seq=4 ttl=51 time=68 ms
64 bytes from 172.217.12.206: icmp_seq=5 ttl=51 time=67 ms
----google.com PING Statistics----
6 packets transmitted, 6 packets received, 0.0% packet loss
round-trip (ms) min/avg/max/med = 67/67/68/67
$ # End of Comment
$ cd /
$ pwd
/
$ exit
exit
Script done, file is typescript
$ pwd
/home/me
现在,我们来看一下生成的文件。不要尝试head
或cat
,因为您不会看到我们遇到的问题(或功能,如果您想使用'^ C')。
这是vim typescript
的前几行
您将看到转义和控制序列。可以将其删除(请参见下面的清理输出部分。)
现在,您可以设置一个doxygen
过滤器,就像描述的here
(在这里,因为链接可能会消失)
Doxygen不支持bash脚本文件。虽然这可能使 的意义上,不支持它们(根据以下内容定义bash脚本文件 函数和变量), 应该放入文档中的源代码树。
添加脚本文件而不更改它们是最简单的,因此 氧气输入过滤器。输入过滤器在命令行中可以很好地工作 sed或awk命令,因此我们将在此处做一个简单的命令,让您添加 Doxygen命令以##开头的行。
在Doxyfile中编辑以下行:
FILE_PATTERNS = *.sh *.awk
INPUT_FILTER = "sed -e 's|##|//!|'"
FILTER_SOURCE_FILES = YES
在每个文件的顶部添加简短说明:
## functions for OpenEmbedded, and Jenkins -*- shell-script -*-.
## @author rickfoosusa
## @file
通常任何带有
#
的注释都可以使用,但是对于语言 通过使用诸如asm4doxy.pl之类的过滤器,您可以获得更多文档。 http://rudy.mif.pg.gda.pl/~bogdro/inne/asm4doxy.txt
希望这会为您指明正确的方向。我希望能回来并充实一点。
我使用以下两个文件来摆脱转义序列,即perl
脚本
#!/usr/bin/perl
#
##############################################################################
# Takes escape and control sequences out of the `script` command's output
#
# @file output_scrubbed_script.pl
#
# Okay, I found this all over the internet, it's just my favorite.
# This removes all unwanted junk (control characters, etc) from the output
# of the Linux script command.
# It's imperfect. It struggles with vim, and it doesn't do too well with up
# arrows and tab completion, but I can usually at least see and understand
# what I did.
#
##############################################################################
while (<>)
{
s/ \e[ #%()*+\-.\/]. |
\r | # Remove extra carriage returns also
(?:\e\[|\x9b) [ -?]* [@-~] | # CSI ... Cmd
(?:\e\]|\x9d) .*? (?:\e\\|[\a\x9c]) | # OSC ... (ST|BEL)
(?:\e[P^_]|[\x90\x9e\x9f]) .*? (?:\e\\|\x9c) | # (DCS|PM|APC) ... ST
\e.|[\x80-\x9f] //xg;
1 while s/[^\b][\b]//g; #remove all non-backspace followed by backspace
print;
}
和一个bash
脚本
#!/bin/bash
#
##############################################################################
# Runs the clean-up
#
# @file script_scrubber.sh
# @author bballdave025
#
# See the usage variable
#
##############################################################################
usage="Usage is:\n > script_scrubber.sh <unscrubbed-file> "\
"[<alternate-filename>]\n"\
"If no <alternate-filename> argument is given, the <unscrubbed-file> \n"\
"will be cleaned in place.\n\n"\
"This script takes the output of the Linux script command and cleans"\
"control characters and other unwanted artifacts."\
"It uses output_scrubbed_text.pl\n"
scrubber_path="$HOME"
scrubber_location="${scrubber_path}/output_scrubbed_text.pl"
if [[ ! -f "${scrubber_location}" ]]; then
echo -e "Fatal error! ${scrubber_location} does not exist."
exit 1
fi #endof: if [[ -f "${location}/output_scrubbed_text.pl" ]]
if [[ ! -x "${scrubber_location}" ]]; then
chmod +x "${scrubber_location}"
fi #endof: if [[ ! -x "${scrubber_location}" ]]
if [[ $# -eq 0 ]]; then
echo "No argument given."
echo -e "${usage}"
exit 2
elif [[ $# -eq 1 ]]; then
if [[ $1 == "--help" ]]; then
echo -e "${usage}"
exit 0
else
"${scrubber_location}" $1 > tmp && mv tmp $1
fi #endof: if [[ $1 -eq "--help" ]]
elif [[ $# -eq 2 ]]; then
"${scrubber_location}" $1 > $2
else
echo "More than two arguments given."
echo -e "${usage}"
fi #endof: if [[ $# -eq <0,1,2,else> ]