Getting latest snapshot date, causes lock

Hi

Im dumping the latest snapshot date to an file, like so.

restic snapshots latest |head -n3 |tail -n1 |awk '{print $2}' > /tmp/test

But when I do so, restic will not remove the lock file. I found its sufficient for this behaviour, that only the |head part, like so

restic snapshots latest |head

What is the reason for this ? And/Or, what would be an proper way of getting the date of the latest snapshot ? Moving the lock manually every time doesnt feel sane.

Full example

root@myserver:~# restic version
restic 0.16.4 compiled with go1.21.6 on linux/amd64
root@myserver:~# restic list locks
repository NNNNN opened (version 2, compression level max)
root@myserver:~# restic snapshots latest |head
ID        Time                 Host                          Tags        Paths
-----------------------------------------------------------------------------------------------------------------------------------------------
NNNNN  2024-08-09 02:00:01  myserver.local.example.com  cron        /etc/folder1
                                                                         /etc/folder2
                                                                         /etc/folder3
                                                                         /etc/folder4
                                                                         /etc/folder5
                                                                         /etc/folder6
                                                                         /etc/folder7
                                                                         /etc/folder8
root@myserver:~# restic list locks
repository NNNNNN opened (version 2, compression level max)
74d98cNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN441

See Handle SIGPIPE gracefully · Issue #1466 · restic/restic · GitHub . Just reading all output from restic before piping it through head solves the problem.

However, the text output is not guaranteed to be stable and might change if we see a reason to do so. Instead use the --json output and transform it using jq. See Scripting — restic 0.17.0 documentation for some documentation of the JSON output.

Thats awesome, works flawlessly.
I was not aware that restic was able to provide json format as output/response.