Skip to content

Instantly share code, notes, and snippets.

@chris-gillatt
Last active August 20, 2024 03:56
Show Gist options
  • Select an option

  • Save chris-gillatt/591cae2402ef7033c3184b30905af3fa to your computer and use it in GitHub Desktop.

Select an option

Save chris-gillatt/591cae2402ef7033c3184b30905af3fa to your computer and use it in GitHub Desktop.
Mount disks from NAS to Macbook automatically
#!/bin/bash
# Script to mount volumes to Macbook from NAS
# Get Network SSID
NETWORK_SSID=$(networksetup -getairportnetwork en0 | awk -F ': ' '{print $2}') && echo "NETWORK: $NETWORK_SSID"
USER=<user>
HOST=<hostname>
# Function to mount volumes on NAS and use Mac Keychain for credentials
# Note - Hostnames are configured via DHCP on DNS host (usually a router)
mount_volumes () {
osascript <<EOF
mount volume "smb://$USER@$HOST/volume1"
mount volume "smb://$USER@$HOST/volume2"
EOF
} > /dev/null 2>&1
MOUNT_STATUS=$(mount | grep -c "$HOST")
# If expected network SSID, mount volumes
if [[ "$NETWORK_SSID" =~ "<network name>" ]] && \
[[ "$MOUNT_STATUS" -lt 2 ]]; then
mount_volumes
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment