#!/bin/bash

path=$2
age=$3

if [ ! -d "$path" ];
then
 mkdir -p $path
fi

if [ -d "$path" ];
then
 find  $path -maxdepth 1 -type f -ctime +$age  -delete
fi

while read -r address folder username password
 do
   if [[ "$(awk -F "" '{print $1}' <<< "$address")" == "#" ]];
   then
    echo "skiping line"
   else
    echo $folder
    arcname=$path/"$address"_"$folder"_`date +%d-%m-%y_%H:%M:%S`
    arcname=$(echo "$arcname" | sed "s/ /_/g")
    smbclient "//$address/$folder" -U "$username%$password"  -d0 -Tc -  | gzip > "$arcname.tar.gz"
   fi
 done < $1
