#!/bin/bash BACKUP_TARGET_DIR="/mnt" function FindSmbSystems { OUR_A_BLOCK=`/sbin/ifconfig eth0 | grep "inet addr" | cut -d: -f2-|gawk '{print $1}'|cut -d. -f1` COMPUTERS=`findsmb | grep ^$OUR_A_BLOCK | gawk '{print $1}'` SMB_SYSTEMS="" for POSIBLE_SMB in $COMPUTERS; do NEW_SMB_SYSTEM=`nmblookup -A $POSIBLE_SMB | grep "\" | head -n 1 | gawk '{print $1}'` if [ ! "$NEW_SMB_SYSTEM" = "" ]; then echo "SMB_SYSTEM = $NEW_SMB_SYSTEM" if [ "$SMB_SYSTEMS" = "" ]; then SMB_SYSTEMS="$NEW_SMB_SYSTEM:$POSIBLE_SMB" else SMB_SYSTEMS="$SMB_SYSTEMS $NEW_SMB_SYSTEM:$POSIBLE_SMB" fi fi done #echo "SMB_SYSTEMS = #$SMB_SYSTEMS" echo -e "\n\n\n" } function FindMyDocumentsShars { for SMB_SERVER in $SMB_SYSTEMS; do SMB_SERVER_NAME=`echo $SMB_SERVER | cut -d: -f1` SMB_SERVER_IP=`echo $SMB_SERVER | cut -d: -f2` #echo "smbclient -L //$SMB_SERVER_NAME/ -I $SMB_SERVER_IP -N" SHARED_FOLDERS=`smbclient -L //$SMB_SERVER_NAME/ -I $SMB_SERVER_IP -N | grep "My Documents"` if [ ! "$SHARED_FOLDERS" = "" ]; then echo "Found My Documents shares on //$SMB_SERVER_NAME/ -I $SMB_SERVER_IP" fi done } SMB_SYSTEMS="A3L9V2:192.168.0.95" function MountAndBackupSmbShares { # Now try to mount their My Documents folders and backup their files. for SMB_SERVER in $SMB_SYSTEMS; do SMB_SERVER_NAME=`echo $SMB_SERVER | cut -d: -f1` SMB_SERVER_IP=`echo $SMB_SERVER | cut -d: -f2` #echo "smbclient -L //$SMB_SERVER_NAME/ -I $SMB_SERVER_IP -N" SHARED_FOLDERS=`smbclient -L //$SMB_SERVER_NAME/ -I $SMB_SERVER_IP -N | grep -i "My Documents"` if [ ! "$SHARED_FOLDERS" = "" ]; then echo "Found My Documents shares on //$SMB_SERVER_NAME/ -I $SMB_SERVER_IP" mkdir /tmp/$SMB_SERVER_NAME cd /tmp smbmount //$SMB_SERVER_NAME/My\ Documents ./$SMB_SERVER_NAME/ $SMB_SERVER_IP -o password=n tar cvfj $BACKUP_TARGET_DIR/$SMB_SERVER_NAME.SMB.tbZ ./$SMB_SERVER_NAME/ smbumount ./$SMB_SERVER_NAME/ rmdir ./$SMB_SERVER_NAME/ fi done } MountAndBackupSmbShares exit