0

我正在使用 rsync 命令来获取文件信息:

info = subprocess.Popen(['sshpass', '-p', password, 'rsync', '-az', '--status', '--dry-run', source],
                           stdout=subprocess.PIPE)

我得到这样的输出:

drwxr-xr-x          4,096 2013/01/23 08:48:35 my_files
-rw-r--r--      5,009,545 2013/01/16 04:20:48 my_files/NC_008253.fna
-rw-r--r--      5,009,545 2013/01/16 04:20:52 my_files/ok.txt
-rw-r--r--      5,009,545 2013/01/16 04:21:08 my_files/test.data

Number of files: 4 (reg: 3, dir: 1)
Number of created files: 0
Number of deleted files: 0
Number of regular files transferred: 0
Total file size: 15,028,635 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 135
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 25
Total bytes received: 147

sent 25 bytes  received 147 bytes  11.10 bytes/sec
total size is 15,028,635  speedup is 87,375.78 (DRY RUN)

我想解析之前的数字bytes/sec i.e 11.10。我怎样才能做到这一点?另外,是服务器的带宽速度吗?

4

1 回答 1

0

好吧,如果你不想做正则表达式并且命令的输出是一致的,那么简单的事情就可以了:

speed = float(info.split("\n")[-2].split(" ")[-2])

不过,不知道这是否是服务器的速度。

于 2013-02-11T13:13:54.173 回答