bash:使用notify-send发送rsync状态

bash:使用notify-send发送rsync状态

我用来rsync将一些更改推送到服务器,为此我制作了一个 bash 脚本,并且我想在桌面上显示状态通知(我正在使用 Linux Mint 18 Cinnamon)

是否可以将输出发送rsyncnotify-send以便我可以看到同步的数据量?这是我实际的 bash 脚本:

notify-send "sincronizando esteticas"
rsync -tprvkku --exclude "00_docs" --exclude "temp" --exclude "config.php" --progress public_html/ rsync://myserver:/myfiles 
notify-send "sincronizacion terminada"

答案1

如果您想要一个通知弹出窗口保留最后的摘要行,例如

sent 6,673,231 bytes  received 17,718 bytes  13,381,898.00 bytes/sec
total size is 6,613,892  speedup is 0.99

然后您可以将 rsync 输出捕获到文件中,并使用文件的最后两行:

rsync ... | tee /tmp/out
notify-send "$(tail -2 /tmp/out)"

如果您想要更详细的摘要,请添加--info=stats2

rsync --info=stats2 ... | tee /tmp/out
notify-send "$(tail -16 /tmp/out)"

这将提供额外的信息,例如:

Number of files: 932 (reg: 929, dir: 2, link: 1)
Number of created files: 932 (reg: 929, dir: 2, link: 1)
Number of deleted files: 0
Number of regular files transferred: 929
Total file size: 6,613,892 bytes
Total transferred file size: 6,613,888 bytes
Literal data: 6,613,888 bytes
Matched data: 0 bytes
File list size: 0
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 6,673,231
Total bytes received: 17,686

相关内容