简体   繁体   English

Bash 命令时间输出到 .txt

[英]Bash command time output to .txt

Hello I have a bash script that I made intending to measure the time elapsed, CPU% and Memory usage of the script download_test.sh with the output being put into a .txt file with the desired output like :您好,我有一个 bash 脚本,我打算用它来测量脚本download_test.sh的时间流逝、CPU% 和内存使用情况,并将输出放入一个 .txt 文件中,其中包含所需的输出,例如:

Elapsed time: 1263.75s
Memory usage: 62916 KB
CPU usage: 0%

The script that executes this looks like:执行此操作的脚本如下所示:

#!/bin/bash
echo 'RESULTS' >> log.txt
{ /usr/bin/time -f 'Elapsed time: %es\nMemory usage: %M KB\nCPU usage: %P' bash download_test.sh  1 ; }  2>> log.txt

However the download terminal progress is also being directed to the .txt file ie然而,下载终端进度也被定向到 .txt 文件,即

RESULTS

Downloading:  95%|#########5| 827M/870M [00:00<?, ?B/s]
Downloading:  95%|#########5| 828M/870M [00:00<00:11, 3.68MB/s]
...
Elapsed time: 14.67s
Memory usage: 62592 KB
CPU usage: 0%

I am new to using stderr and stdout so have I misunderstood them and how would I resolve this issue?我是使用 stderr 和 stdout 的新手,所以我误解了它们,我该如何解决这个问题?

I don't think this is stderr .我不认为这是stderr You can use below command to print required rows.您可以使用以下命令打印所需的行。

awk '/Elapsed/,/CPU/'

Try this尝试这个

#!/bin/bash
echo 'RESULTS' >> log.txt
{ /usr/bin/time -f 'Elapsed time: %es\nMemory usage: %M KB\nCPU usage: %P' bash download_test.sh  1 ; } | awk '/Elapsed/,/CPU/' 2>> log.txt

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

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