Page 1 of 2

Name instead of IP for SAMBA shares

Posted: Wed Apr 25, 2012 7:11 pm
by brunogts77
Hi, it?s possible to configure samba in order to see the all shared devices on the network by name and not by your ip?

AW: Samba on D5700

Posted: Thu Apr 26, 2012 8:50 pm
by DEUS
Ok found it by myself, this might be possible by get hostname via arp or lookup and then use it instead of IP. But you need to modify initi script. Normally nmbd is used to get hostname front wins

Re: Samba on D5700

Posted: Thu Apr 26, 2012 10:16 pm
by brunogts77
Can you help me to modify the init script?

Re: Samba on D5700

Posted: Thu Apr 26, 2012 11:40 pm
by DEUS
to get the right hostname if nmblookup is there modification should be easy

Code: Select all

$DISTROOT/usr/bin/nmblookup -A "IP" | /bin/busybox awk 'NR==2 { print $1}'

Re: Samba on D5700

Posted: Fri Apr 27, 2012 12:10 pm
by brunogts77
DEUS wrote:to get the right hostname if nmblookup is there modification should be easy

Code: Select all

$DISTROOT/usr/bin/nmblookup -A "IP" | /bin/busybox awk 'NR==2 { print $1}'
Thanks Deus. But, where do I put this "$DISTROOT/usr/bin/nmblookup -A "IP" | /bin/busybox awk 'NR==2 { print $1}" Code?

This is my smb fille:
    . /dtv/SGO.env
    # sleep 9
    ##### CHANGE MEEEEE !!!!! ######
    USER="sysadmin"
    PASSWD="123456789"
    PERM="rw" # can be ro or rw
    ##### CHANGE MEEEEE END ######

    rm -fr /mtd_contents/database/

    [ -e /mtd_rwarea/smb_userdata ] && source /mtd_rwarea/smb_userdata
    [ -z $USER ] && exit 1
    [ -z $PASSWD ] && exit 1

    DEST_DIR=$MOUNT_PATH/smb
    SERVER=""
    # SERVER="10.0.0.1" # if you want a fixed server
    SHARES=""
    FR_NAME="Samba Server"
    # M_OPTS="rw,user=${USER},password=${PASSWD}"
    M_OPTS="$PERM,user=${USER},password=${PASSWD},codepage=cp1250,iocharset=utf8"

    SERVERS="Don't set me!!"

    do_mount()
    {
    # $(echo -e "[sdh]\nVendor : CifsMount\nProduct : $FR_NAME\n\
    #Serial : Q80VQLFH\nDevpath : 8\nLun : 0\nMountDir : $DEST_DIR\nFileSystem : vfat\n" >> /dtv/usb/log)

    for i in $S_MOUNTS ; do
    i="$(echo -n $i | sed -e 's/SGOspace/ /g')"
    M_POINT="$DEST_DIR/$1/$(echo -n $i | sed -e "s/\\\$/_/g")"
    mkdir -p "$M_POINT"
    if [ `cat /proc/mounts | grep -c "$M_POINT"` -lt "1" ] ; then
    /bin/busybox mount -o "${M_OPTS}" -t cifs "//$1/$i" "$M_POINT"
    else
    echo "$M_POINT is mounted!"
    fi

    done
    }

    get_shares()
    {
    echo "Search Shares"
    for i in $SERVERS ; do
    echo "on: $i"
    S_MOUNTS=$(smbclient -s "$SYSROOT/etc/samba/smb.conf" -U ${USER}%${PASSWD} \
    -g -L $i | grep "Disk|" | grep -v "\\$" | grep -v " Service" | sed -r 's/.*\|(.*)\|.*/\1/' | sed -r 's/ /SGOspace/g')
    # -g -L $i | grep "Disk|" | grep -v "\\$" | grep -v " Service" | cut -d "|" -f2)
    [ -n "$S_MOUNTS" ] && do_mount $i
    done
    }

    get_servers()
    {
    if [ -z "$SERVER" ] ; then
    # SERVERS=$(cat /proc/net/arp | grep -v "IP address" | cut -d " " -f1)
    SERVERS=$(cat /proc/net/arp | grep -v "IP address" | sed 's/^\(\w*.\w*.\w*.\w*\) *.*/\1/')
    else
    SERVERS=$SERVER
    fi
    }

    case $1 in
    start)
    insmod $MOD_DIR/kernel/fs/cifs/cifs.ko
    mkdir -p "$DEST_DIR"
    get_servers
    get_shares
    ;;
    stop)
    # may can fail if device access the mount from content library
    # for i in $(cat /proc/mounts | grep cifs | cut -d " " -f2) ; do
    for i in $(cat /proc/mounts | grep cifs | grep "$DEST_DIR" | sed 's/^\(.*\) \(.*\) cifs .*/\2/') ; do
    i="$(echo -n $i | sed -r 's/\\040/ /g')"
    /bin/busybox umount "$i"
    done
    ;;
    status)
    /bin/mount | grep "$DEST_DIR"
    ;;
    *)
    echo "Usage: $0 {start|stop}" 1>&2
    exit 0
    ;;
    esac

    Re: Samba on D5700

    Posted: Fri Apr 27, 2012 12:42 pm
    by juusso
    brunogts77 wrote:...
    Some general forum rules:
    Please use tags for your code (debug output, scripts, bash commands and so on.)
    Quote just only important, but not whole posts.
    tag_code.PNG
    This helps to understand you better. Thanks for understanding. :!:

    Re: Samba on D5700

    Posted: Tue May 01, 2012 10:43 am
    by brunogts77
    Anny help?? Where do I put this "$DISTROOT/usr/bin/nmblookup -A "IP" | /bin/busybox awk 'NR==2 { print $1}" Code?

    Re: Samba on D5700

    Posted: Tue May 01, 2012 1:49 pm
    by DEUS
    first you are just requesting help so be patient, did you tried it by yourself? no success?
    original line

    Code: Select all

    M_POINT="$DEST_DIR/$1/$(echo -n $i | sed -e "s/\\\$/_/g")"
    for name resolution via wins

    Code: Select all

    M_POINT="$DEST_DIR/$($DISTROOT/usr/bin/nmblookup -A "$1" | /bin/busybox awk 'NR==2 { print $1}')/$(echo -n $i | sed -e "s/\\\$/_/g")"
    for name resolution via dns

    Code: Select all

    M_POINT="$DEST_DIR/$($SYSROOT/bin/busybox nslookup "$1" | /bin/busybox awk 'NR==5 { print $4}' | /bin/busybox awk -F '.' '{ print $1}')/$(echo -n $i | sed -e "s/\\\$/_/g")"
    
    maybe you see how easy this could be just did a quick test and works in my enviorment

    Re: Samba on D5700

    Posted: Tue May 01, 2012 5:14 pm
    by brunogts77
    Thanks Deus. It works fine! Very, very, very thanks.

    Re: Samba on D5700

    Posted: Thu May 03, 2012 11:03 pm
    by Spoza
    Can this be included in the extensions pack? It seems to be VERY useful step towards average users.