Have several thoughts about error messages, in reply to SL's comments.
Here's one, maybe more later...

On Thu, 31 Jan 2008 09:48:37 -0800
Steve Langasek <[EMAIL PROTECTED]> wrote:

> > This requires the program's internal error checking logic to
> > distinguish between server names and share names.  Which it probably
> > should, if it doesn't already.
> 
> A fine suggestion, but unless you plan to provide a patch, please
> discuss this with upstream directly; this is going to be low enough
> down my todo list that I'm unlikely to ever work on it.

There are high level ways to do it, i.e. a wrapper script.  Attached is
a runnable script that shows the concept, and also may be useful to
users** in the same boat:

        # cifs_samba_check.sh host share
        % cifs_samba_check.sh 192.168.1.51 hdb1 ; echo $?
        host 192.168.1.51 exists
        samba/cifs ports present on 192.168.1.51
        share hdb1 exists
        0

        % cifs_samba_check.sh 192.168.1.51 hdb9 ; echo $?
        host 192.168.1.51 exists
        samba/cifs ports present on 192.168.1.51
        can't find share hdb9
        3

        % ~/cifs_samba_check.sh 192.168.1.59 hdb9 ; echo $?
        can't find host 192.168.1.59
        1

(Haven't put in a util check or '--help' yet...)

(**if necessary: apt-get install nmap host smbclient )

High level net utils are called from three true/false functions:

        host_exist()  # syntax: host_exist host
        { host $1 > /dev/null 2> /dev/null ; }

        # ports 139 & 445 are a bit of a guess.
        samba_exist() # syntax: samba_exist host
        { 
                [ `nmap -p "139,445" $1 | grep 'tcp open' | wc -l` = 2 ]
        }

        share_grep()    # syntax: share_grep sharename hostname
        {
                smbclient -L $2 -N 2>&1 | \
                grep -A 99 "Sharename       Type      Comment" | \
                egrep -m 1 -B 99 "^$" | tail -n +3 | head -n -1 | \
                grep -q $1
        }

...my networking skills are feeble, and I hope there are better ways of
writing such functions.

HTH...
#!/bin/sh
# cifs_samba_check.sh  v.001
# Demo error checker for what 'mount.cifs' lacks.
# 2007, A. Costa, hereby GPL'd of course...

# 3 true/false functions

host_exist()  
{ host $1 > /dev/null 2> /dev/null ; }

# ports 139 & 445 are a bit of a guess.
samba_exist() 
{ 
    [ `nmap -p "139,445" $1 | grep 'tcp open' | wc -l` = 2 ]
}

share_grep() 	# syntax: sharegrep sharename hostname
{
    smbclient -L $2 -N 2>&1 | \
    grep -A 99 "Sharename       Type      Comment" | \
    egrep -m 1 -B 99 "^$" | tail -n +3 | head -n -1 | \
    grep -q $1
}


HOST=${1:-192.168.1.51}
SHARE=${2:-hdb1}

if host_exist $HOST 
then
    echo "host $HOST exists"
    if samba_exist $HOST
    then
	echo "samba/cifs ports present on $HOST"
	if share_grep $SHARE $HOST
	then
	    echo "share $SHARE exists"
	else
	    echo "can't find share $SHARE"
	    exit 3
	fi
    else
        echo "no samba/cifs ports found on $HOST"
	exit 2
    fi
else
    echo "can't find host $HOST"
    exit 1
fi

Reply via email to