1

Trying to script a file download in Ubuntu from an SMB network server (windows-esque).

I have a folder tree as follows:

  • file1.tar.gz
  • file2.tar.gz
  • file3.tar.gz

These files have different modified dates.

I want to download the latest file using smbclient, get requires a file name which I won't know what the latest file name is (it won't necessarily be in numeric order).

How do I get the last created file using smbclient? Is there a specific mask in mget to do this?

I also hopefully want to do this without any interaction from the user (part of a shell script).

Jamesking56
  • 141
  • 3

1 Answers1

0

Mount share to some directory then use ls -1t to list files sorted according to modification time.

ls -1t /mnt/file*.tar.gz | head -n 1
John Doe
  • 101
  • 2
  • 1
    I should say, I don't really want to have to mount it just to download a single file... – Jamesking56 Jun 07 '18 at 08:45
  • mount/ls/cp/umount will be a bit faster than several smbclient invocations because internally smbclient will do the same low level operations. – John Doe Jun 08 '18 at 10:01