Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exit codes of smbclient

i've a problem with the commandline command "smbclient" of samba on arm.

I wrote a script to download files from a Windows Share. Here the smb-part of this script.

smbclient  //CNAME/SNAME -I0.0.0.0 -N -c "case_sensitive; cd folder; prompt; mget file"
echo $?

My problem ar the exit codes. If the file is downloaded completely, the exit code is 0 (OK) If the file cannot be downloaded, the exit code is 1 (OK) If the testmaschine loses the connection to the share due downloading a file, the exit code is 0 (NOT GOOD), but error ("Lost connection...etc.") is written to console. (OK)

I tried it with two different versions. samba-3.0.32 samba-3.6.19 Both the same.

Does someone know a good workaround (or smbclient-argument) to let my script know, that the download failed?

PS. I checked the smbclient sources. It looks like they forgot to set the exitcode. Because everytime there is another error the set the Errormessage and do an (e.g. exit(1)). But for timeouts, they only set the Errormessage.

Thank you in advance!

like image 628
Korbi Avatar asked Nov 06 '13 06:11

Korbi


People also ask

What does Smbclient mean in Linux?

smbclient is a client that is part of the Samba software suite. It communicates with a LAN Manager server, offering an interface similar to that of the ftp program.

What protocol does Smbclient use?

The SMB client file system in the AIX operating system requires Kerberos-based GSSAPI to start the user-authenticated session by using the SMB protocol version 2.1 or version 3.0. 2. In the AIX operating system, the GSSAPI is provided by a Userspace Library in the IBM® Network Authentication Service (NAS) version 1.16.

Can Smbclient be used in a script?

This is particularly useful in scripts and for printing stdin to the server, e.g. -c 'print -'. smbclient disconnects when it is finished executing the commands.

How do I use Smbclient in Windows?

Using smbclient Basic use is fairly straightforward: type smbclient , followed by a NetBIOS name and share name in the form // SERVER / SHARE . The result is a prompt for a password followed by smbclient's own prompt. You can then type FTP-style commands, such as dir, get, put, and exit.

Which parameter of Smbclient program is used to set the workgroup name?

The name required is a NetBIOS server name, which may or may not be the same as the IP hostname of the machine running the server. The server name is looked up according to either the -R|--name-resolve parameter to smbclient or using the name resolve order parameter in the smb.


1 Answers

What would be best is to use the -E argument to smbclient and redirect 2>/errorlog from the command line. You can then check this file to see if any errors occurred.

Warning, the first line is always the Domain=......... so you may need to strip that line out.

Something like this:

smbclient Hostname -A authfile -E 1>log 2>errorlog <<-EOF 
get foo 
EOF

In the errorlog you should find something like below, your log file will be empty

Domain=[Hostname] OS=[Windows Server 2008 R2 Standard 7601 Service Pack 1] Server=[Windows Server 2008 R2 Standard 6.1] NT_STATUS_OBJECT_NAME_NOT_FOUND opening remote file \foo

like image 153
Timda Avatar answered Sep 18 '22 12:09

Timda