在Bash中定时卷曲操作

时间:2009-09-21 04:44:41

标签: bash time

我想知道使用Curl将一批文件提交到在localhost上运行的HTTP服务器并将其写入文件需要多长时间。我无法正确理解语法。

export TIMEFORMAT="%R"
time -ao times.dat ( curl -v -d @1.batch -X POST $DB )

我怎样才能做到这一点?我想这只是使用shell语法的问题。

2 个答案:

答案 0 :(得分:5)

指定time的完整路径(不需要括号):

export TIME="%e"
/usr/bin/time -ao times.dat curl -v -d @1.batch -X POST $DB

请注意,使用不同的环境变量和不同的说明符来获取经过的时间。

time是Bash关键字,不支持选项-a-o

/usr/bin/time是一个外部二进制文件。

$ type -a time
time is a shell keyword
time is /usr/bin/time
$ help time
time: time [-p] PIPELINE
    Execute PIPELINE and print a summary of the real time, user CPU time,
    and system CPU time spent executing PIPELINE when it terminates.
    The return status is the return status of PIPELINE.  The `-p' option
    prints the timing summary in a slightly different format.  This uses
    the value of the TIMEFORMAT variable as the output format.
$ man time
TIME(1)                                                                TIME(1)

NAME
       time - run programs and summarize system resource usage

SYNOPSIS
       time   [ -apqvV ] [ -f FORMAT ] [ -o FILE ]
              [ --append ] [ --verbose ] [ --quiet ] [ --portability ]
              [ --format=FORMAT ] [ --output=FILE ] [ --version ]
              [ --help ] COMMAND [ ARGS ]

DESCRIPTION
       time  run  the  program  COMMAND with any given arguments ARG....  When
       COMMAND finishes, time displays information  about  resources  used  by
       COMMAND  (on  the standard error output, by default).  If COMMAND exits
       with non-zero status, time displays a warning message and the exit sta‐
       tus.
       .
       .
       .

答案 1 :(得分:0)

time不适合记录持续时间。

但你可以这样做:

date >> $LOGFILE
# your operation here
date >> $LOGFILE

如果您想监控每个文件的统计信息,那么您始终可以将curl包裹在for循环中。

相关问题