LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   automouter samba (https://www.linuxquestions.org/questions/linux-software-2/automouter-samba-443289/)

Xerop 05-09-2006 09:58 PM

automouter samba
 
I need a script or some sort of software that would be able to check the available shares on a specific target machine (with smbclient or smbmount) make directories for each share in a specific folder then loop through and mount all available shares. I need this script because I have a scpecific computer that constantly changes its shares and I am tired of manualy mounting each needed share. If someone could point me in the right direction I would be greatful.

I can get a list of shares in the following table format.
<tab>Share_name<spaces>"Disk"<newline>

a Disk
asdas Disk
lakjsh Disk
l;akjsd Disk

replace <tab> with a tab character and <spaces> with spaces.
If someone could tell me how to extract the share name by it self from maybe 10 lines (with a loop)
I also would like to set a variable equal to one of the share names and mount it then loop through all the lines to complete the mounting.

This should end up to be a simple bash script or sh script that could be run at the start of kde!

Xerop 05-10-2006 08:48 PM

bump*
anyone? can someone show me how to just extract the names from the table?

Xerop 05-11-2006 06:06 PM

well I compiled the solution on my own using some online scripts. I do not know bash so this might not be optimal but it works
Code:



#!/bin/bash
declare -a lines
exec 3</home/user/smb || exit 1
while read curline <&3; do
    if [ -z "$curline" -o "${curline:0:1}" = "#" ]; then continue; fi
    lines=("${lines[@]}" "$curline")
done
exec 3<&-


#COUNT=0
#      while [ $COUNT -lt 22 ]; do
#command        umount /mnt/server/${lines[$COUNT]}
#let COUNT=COUNT+1
#done

command smbclient -L -N //server

COUNTER=0
        while [  $COUNTER -lt 22 ]; do
            echo mounting //server/${lines[$COUNTER]}
command smbmount //server/${lines[$COUNTER]} /mnt/server/${lines[$COUNTER]} -o guest
#      sleep 1
            let COUNTER=COUNTER+1
        done

/home/user/smb is the path to the file which contains the share names. //server is the samba name of your pc which has the shares. maybe this will help someone

cs-cam 05-11-2006 08:15 PM

Excellent work! I only just saw this thread which is weird but hey, great job working it out and thank you for taking the time to post it for others :)

archtoad6 05-15-2006 08:45 AM

I too just saw this, & echo the 2 compliments.

I do think your script could be way simpler, or else I don't understand what you are trying to do. Assuming your "list of shares in the following table format" is in a file (SHARES) & the command that will mount a share is smbmount //server/share /mnt/server/share -o guest where "share" is the current share, then would this not work:
Code:

#!/bin/bash

# set the share table file
SHARES=<share_table_file>

for S in `awk '{print $1}' $SHARES`
do
  smbmount //server/$S /mnt/server/$S -o guest
done



All times are GMT -5. The time now is 07:21 AM.