I am getting some files via an smb client (I use version 4.13.14-Ubuntu) command:
smbclient //<myip>/<myshare> -c "prompt;cd myPath; mget *.csv;" -U <myuser> 2> logs.txt
This command results in the text file containing
getting file \myPath\dde_DC-Machine-99999901-DeviceId_20210624.csv of size 3710 as dde_DC-Machine-99999901-DeviceId_20210624.csv (13.6 KiloBytes/sec) (average 13.6 KiloBytes/sec)
Which shows the file has been successfully downloaded (which is actually the case, the file is completely available after executing the command).
However, as you see from the standard error redirection "2>", the logs on success are written to stderr where I would expect them on stdout.
Now when I add some invalid parameters like a non existing path
smbclient //<myip>/<myshare> -c "prompt;cd nonExistingPath; mget *.csv;" -U <myuser> 2> logs.txt
The terminal prints NT_STATUS_OBJECT_NAME_NOT_FOUND which is correct but coming from the standard out whereas the standard error is empty.
It almost looks like the client writes to the stdout if an error occurs and to the stderr if everything works fine, so exactly the wrong way around. Beware this happens only when using the mget or get commands, other commands I've tested seem to work as they should.
Question
Is there a bug in the smbclient, or a misunderstanding from my side?
Check if Samba config file (/usr/local/samba/lib/smb.conf) contains the '-E'.
"-E Sends output from commands to stderr instead of stdout."