是否有工具可以清理 script(1) 工具的输出?

发布于 2024-07-22 06:18:00 字数 429 浏览 6 评论 0原文

script(1) 是一个用于保存交互式终端会话记录的工具; 默认情况下,它写入文件transcript。 我的问题是,我使用 ksh93,它具有 readline 功能,因此转录内容被各种终端转义序列搞乱,并且很难重建实际执行的命令。 更不用说那些杂散的^M之类的了。

我正在寻找一个工具,可以读取由 script 编写的转录文件,删除所有垃圾,并重建 shell 认为它正在执行的内容,所以我有一些显示 $PS1 以及实际执行的命令。 如果做不到这一点,我正在寻找有关如何编写此类工具的建议,最好使用 terminfo 数据库中的知识,或者如果做不到这一点,则仅使用 ANSI 转义序列。

看看 shell 历史的作弊,只要它确实有效,也是可以接受的。

script(1) is a tool for keeping a record of an interactive terminal session; by default it writes to the file transcript. My problem is that I use ksh93, which has readline features, and so the transcript is mucked up with all sorts of terminal escape sequences and it can be very difficult to reconstruct the command that was actually executed. Not to mention the stray ^M's and the like.

I'm looking for a tool that will read a transcript file written by script, remove all the junk, and reconstruct what the shell thought it was executing, so I have something that shows $PS1 and the commands actually executed. Failing that, I'm looking for suggestions on how to write such a tool, ideally using knowledge from the terminfo database, or failing that, just using ANSI escape sequences.

A cheat that looks in shell history, as long as it really really works, would also be acceptable.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

錯遇了你 2024-07-29 06:18:00

默认情况下,cat/more 不能用于浏览成绩单吗? 您是否打算根据实际执行的命令创建脚本(根据我的经验,这可能很危险)?

不管怎样,三年了没有答案,所以我会用一个不完整的解决方案来尝试一下。 如果您只对实际键入的命令感兴趣,请删除不可打印的字符,然后将 PS1' 替换为可读且唯一的内容,然后 grep 查找该唯一字符串。 像这样:

$ sed -i 's/[^[:print:]]//g' transcript

$ sed 's/]0;cartman@southpark: ~cartman@southpark:~/CARTMAN/g' transcript | grep CARTMAN

解释:在第一次 sed 之后,PS1' 可以从转录文件的前几行之一中获取,因为 - PS1' 与 PS1 不同 - 并且可以使用唯一的可读字符串(“CARTMAN “ 这里)。 请注意,提示末尾的美元符号是故意省略的。

在我尝试的几个例子中,这并没有解决所有问题,但解决了大多数问题。

Doesn't cat/more work by default for browsing the transcript? Do you intend to create a script out of the commands actually executed (which in my experience can be dangerous)?

Anyway, 3 years without an answer, so I will give it a shot with an incomplete solution. If your are only interested in the commands actually typed, remove the non-printable characters, then replace PS1' with something readable and unique, and grep for that unique string. Like this:

$ sed -i 's/[^[:print:]]//g' transcript

$ sed 's/]0;cartman@southpark: ~cartman@southpark:~/CARTMAN/g' transcript | grep CARTMAN

Explanation: After first sed, PS1' can be taken from one of the first few lines of the transcript file, as is -- PS1' is different from PS1 -- and can be modified with a unique readable string ("CARTMAN" here). Note that the dollar sign at the end of the prompt was left out intentionally.

In the few examples that I tried, this didn't solve everything but took care of most issues.

戈亓 2024-07-29 06:18:00

这本质上与最近在 我可以使用 unix utils 以编程方式将 ANSI 控制代码“烧入”到文件中吗? -- 删除所有非打印字符不会修复

  • 嵌入的转义序列
  • 退格/重划用于下划线
  • 使用回车- 重打返回

This is essentially the same question asked recently in Can I programmatically “burn in” ANSI control codes to a file using unix utils? -- removing all nonprinting characters will not fix

  • embedded escape sequences
  • backspace/overstriking for underlining
  • use of carriage-returns for overstriking
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文