The Samba-Bugzilla – Bug 10255
smbclient does not return proper exit code for timeout
Last modified: 2015-07-09 03:32:30 UTC
if 'smbclient' loses connection due downloading a file, it fails to return a proper exit code.
call of smbclient:
| $ smbclient //CNAME/SNAME -Ix.x.x.x -N -c "case_sensitive; cd folder; prompt; | mget file"
| echo $?
output (lost connection):
| getting file \folder\file of size 104857600 as file Receiving SMB: Server | stopped responding
| Short read when getting file \folder\file. Only got 90897408 bytes.
| Error Call timed out: server did not respond after 20000 milliseconds closing | remote file
| (1381.3 kb/s) (average 1381.3 kb/s)
This is very problematic when used in scripts.
It will be fixed eventually, but if it is urgent for you you might want to contact someone from https://www.samba.org/samba/support/ got get a quick paid response.
Fixing up the error codes in the smbclient returns paths in on my list of things to do. Unfortunately right now other things have priority. I'll accept the bug and get to it when I can.
It's unfortunate that smbclient is so minimally supported with minimalist commands and incomplete exit codes. Even in its crufty state, smbclient is the only Samba client that meets and exceeds the user accessibility, adaptability, and reliability of the Windows SMB client.
It isn't Samba's fault. Unix like OS don't handle mounts well when the mounted servers disappear, whether Samba, NFS, or anything else. Until I discovered smbclient I was using autofs which is reliable until the server disappears during the mount time window. Losing a mounted server often requires a Linux reboot to fix. Losing a server to smbclient or a Windows BAT file is an easily handled exit code.
smbclient exit codes should be enumerated so we can distinguish:
* Server not found
* Share not found
* Invalid Command
* A command was incomplete
In my case the incorrect exit code comes from this command
$ smbclient '//192.168.1.2/foo' -U 'GUEST%' -c "ls'"
ls': command not found
Fortunately all I want is to test if the supplied server exists and isn't bogus which seems to work with this null command.
$ smbclient '//192.168.1.2/foo' -U 'GUEST%' -c ''