Progress bar during smbclient put

Viewed 6273

I'm trying to show a progress bar during a remote copy using smbclient put, maybe using pv or dialog, or any other option.

The smbclient-put command il working fine:

smbclient //usbrouter/backup --user=myusername mypassword -c "put /media/DOC/BackupAuto/work_backup.tar.gz work_backup.tar.gz"

But I can't find any way the show the progress of the copy. Anyone have a solution/alternative?

Thanks.

2 Answers

As you mentioned pv is perfect for the job:

file="work_backup.tar.gz"
pv "/media/DOC/BackupAuto/${file}" \
  | smbclient \
    --user=myusername%mypassword \
    --command "put - '${file}'" \
    //usbrouter/backup 

Or in the reverse, to pull with progress:

file="work_backup.tar.gz"
size="$( \
  smbclient \
    --user=myusername%mypassword \
    --command "ls '${file}'" \
    //usbrouter/backup \
    2> /dev/null \
    | grep "${file}" \
    | awk '{print $3}')"

smbclient \
  --stderr \
  --user=myusername%mypassword \
  --command "get '${file}' /dev/stdout" \
  //usbrouter/backup \
  | pv -s "${size}" \
  > "/media/DOC/BackupAuto/${file}"

Obligatory side note: you should not specify password like this, use one of the other options like --authentication-file instead

Related