smb_utilities/list_smb_shares.sh

29 lines
991 B
Bash
Executable File

#!/bin/bash
# Define colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
SHARE_DIR="/etc/samba/shares.d"
# Header
printf "${GREEN}%s${NC}\n" "--------------------------------------------------------------------------------------------"
printf "${GREEN}%-20s %-40s %-20s${NC}\n" "SHARE NAME" "PATH" "USER"
printf "${GREEN}%s${NC}\n" "--------------------------------------------------------------------------------------------"
# Loop through share config files
for file in "$SHARE_DIR"/*.conf; do
[ -e "$file" ] || continue # Skip if no .conf files
SHARE_NAME=$(basename "$file" .conf)
PATH_LINE=$(grep -i "^ *path *= *" "$file")
USER_LINE=$(grep -i "^ *valid users *= *" "$file")
# Extract values
SHARE_PATH=$(echo "$PATH_LINE" | cut -d'=' -f2- | xargs)
VALID_USER=$(echo "$USER_LINE" | cut -d'=' -f2- | xargs)
# Print each row with fixed width columns
printf "%-20s %-40s %-20s\n" "$SHARE_NAME" "$SHARE_PATH" "$VALID_USER"
done