Skip to content

Instantly share code, notes, and snippets.

@BaconSoap
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BaconSoap/f3f568aa04f4fd7c230f to your computer and use it in GitHub Desktop.
Save BaconSoap/f3f568aa04f4fd7c230f to your computer and use it in GitHub Desktop.
Script to connect to Windows via command line on an OS X machine
#!/bin/sh
WINDOWSHOST = "//user@guest-hostname"
SHAREDIR = "~/smb"
# make sure the mount dir on host exists
if [ ! -d "$SHAREDIR/$1" ]; then
mkdir "$SHAREDIR/$1"
fi
# if there's something in the mount, because either share is active or files
# are hanging around, cancel the mount process
if find "$SHAREDIR/$1" -maxdepth 0 -empty | read v; then
rm -rf "$SHAREDIR/$1"
mkdir "$SHAREDIR/$1"
mount -t smbfs "$WINDOWSHOST/$1" "$SHAREDIR/$1"
fi
# move into the mount and enumerate all files to fill the cache
cd "$SHAREDIR/$1"
ls -laR > /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment