Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

First and foremost, thank you for your guidance in advance!

I am trying to dyamically mount NAS shares (and exclude others) via a BASH script. I would like to browse an open nas share:

#smbclient -L -N

Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.0.24-1.22_OSSTECH]

        Sharename       Type      Comment
        ---------       ----      -------
        info            Disk      LinkStation Utilities
        share           Disk      LinkStation folder
        Manager         Disk      Managers Private Folder
        IPC$            IPC       IPC Service ("Eucalyptus_Share")
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.0.24-1.22_OSSTECH]

        Server               Comment
        ---------            -------
        EUCALYPTUS           Eucalyptus_Share

        Workgroup            Master
        ---------            -------
        DDDDDOMM             DD-D-21075
        WORKGROUP            EUCALYPTUS

Then grep through the list to remove non-samba-share information and pre-installed information like an "info" share.

share Manager

Basically, out of all of the text returned, I only want to keep the active shares that I know have data in them. So in this case: share & manager, but for the purpose of expansion, I'd like to code it inversely. I.e. instead searching for share & manager, i want to and identify and exclude everything else, leaving just share & manager. That way, if I later add SCANS, share, manager & scans will now automatically update..

In combination, I currently have a working backup script that executes based on the share name I pass through to it.

I'd VERY much like to create a loop that goes out, grabs the share names, and passes them to the backup script in this format:

./backup.sh share1 share2

./backup.sh Manager share

What would be the best method to grab the existing shares, filter out details I do not want (Grep? or --exclude?) then have it laid out nicely to echo the share names in a "one-liner"

How can I do this ?

share|improve this question
This calls the NAS box, filters everything but disks, then pipes the first word from each line returned. Finally, I filter out the pre-installed shares (info & it). My last question woudl be to append this to the end of a script: ./backup.sh + smbclient -L -N | grep -i Disk | awk '{print $1;}' | grep -v -i info | grep -v -i it –  user218427 Nov 22 '13 at 23:01
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.