Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何记录每个命令';s持续时间/结果,并用“历史记录”显示此信息?_Linux_Bash_Zsh - Fatal编程技术网

Linux 如何记录每个命令';s持续时间/结果,并用“历史记录”显示此信息?

Linux 如何记录每个命令';s持续时间/结果,并用“历史记录”显示此信息?,linux,bash,zsh,Linux,Bash,Zsh,我有一些命令需要很长时间才能运行。我希望能够在历史上记录所有这些事件 我已经查看了历史标记,但这些标记似乎只显示命令启动的时间/日期和状态代码。部分回答了您的问题,我在.zshrc中提供了一个函数,用于在命令耗时超过10秒时发送桌面通知 您可以调整以构建自己的历史文件 (要获得通知,您必须具有notify send或adapt$NOTIFYER) (改编自Contrapuntus.net上的这篇文章)我将使用time(1)实用程序为您的长命令制作一个包装器。它具有功能丰富的日志功能。对于bash

我有一些命令需要很长时间才能运行。我希望能够在历史上记录所有这些事件


我已经查看了历史标记,但这些标记似乎只显示命令启动的时间/日期和状态代码。

部分回答了您的问题,我在
.zshrc
中提供了一个函数,用于在命令耗时超过10秒时发送桌面通知

您可以调整以构建自己的历史文件

(要获得通知,您必须具有notify send或adapt
$NOTIFYER


(改编自Contrapuntus.net上的这篇文章)

我将使用time(1)实用程序为您的长命令制作一个包装器。它具有功能丰富的日志功能。对于bash,请使用它的完整路径,否则将获得有限的bash内置版本。
notifier=notify-send
if [[ ${TERM[1,5]} == xterm ]]; then
    preexec() {
        notifiable_cmd=$1
        notifiable_start_time=`date +%s`
    }

    precmd() {
        if (( $? == 0 )); then
            notifiable_status="Success in "
        else
            notifiable_status="Failed in "
        fi
        if [[ "$notifiable_cmd" != "" ]]; then
            (( notifiable_time = `date +%s` - $notifiable_start_time ))
            if [[ $notifiable_time -ge 60 ]]; then
                notifiable_str_time="$(($notifiable_time%100000/60)) min $(($notifiable_time%60)) s"
            else
                notifiable_str_time="$notifiable_time[1,5] s"
            fi
            if [[ $notifiable_time -gt 10 ]]; then
                $notifier $notifiable_cmd "$notifiable_status $notifiable_str_time"
            fi
        fi
        notifiable_cmd=
    }
fi