Created
February 21, 2012 06:16
-
-
Save vena/1874170 to your computer and use it in GitHub Desktop.
[OS X 10.7] autofs executable map to mount all SMB shared from a given server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
##################################### | |
# Save this to /etc/auto_smb | |
# Set execution bit with chmod +x /etc/auto_smb | |
# Add this in /etc/auto_master as: | |
# /mountpoint auto_smb | |
# | |
# Create .smb_credentials file in user home dir | |
# format: | |
# username=[username] | |
# password=[password] | |
##################################### | |
LOCAL_USER=myuser | |
SMB_SERVER=myserver | |
OPTIONS="-fstype=url" | |
CACHE_TIME=900 | |
if [ -e /Users/${LOCAL_USER}/.smb_credentials ]; then | |
. /Users/${LOCAL_USER}/.smb_credentials | |
SERVER=$username:$password@$SMB_SERVER | |
else | |
SERVER=$SMB_SERVER | |
fi | |
if [ $# = 0 ]; then | |
if [ -e /tmp/.smb_cache ]; then | |
eTime=`date +%s` | |
eval $(stat -s -t %s /tmp/.smb_cache) | |
if [ $(($eTime-$st_mtime)) -lt $CACHE_TIME ]; then | |
cat /tmp/.smb_cache | |
exit 0 | |
fi | |
fi | |
rm -rf /tmp/.smb_cache | |
sudo -u $LOCAL_USER smbutil view //$SERVER | grep Disk | sed 's/ *Disk *$//;s/ *$//g;s/^$//g' | while read MOUNT; | |
do | |
if [ -n "$MOUNT" ]; then | |
echo "\"${MOUNT}\" ${OPTIONS} cifs://$SERVER}/\"${MOUNT}\"" | tee -a /tmp/.smb_cache; | |
chmod 0600 /tmp/.smb_cache | |
fi | |
done | |
exit 0 | |
fi | |
echo "${OPTIONS} cifs://${SERVER}/\"$1\"" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Cycles through SMB shares from server and cds into each as the specified user | |
# Setting this script as a launch daemon on a calendar schedule can be useful | |
LOCAL_USER=myuser | |
LOCAL_MOUNT=/mnt | |
SMB_SERVER=myserver | |
if [ -e /Users/${LOCAL_USER}/.smb_credentials ]; then | |
. /Users/${LOCAL_USER}/.smb_credentials | |
SERVER=$username:$password@$SMB_SERVER | |
else | |
SERVER=$SMB_SERVER | |
fi | |
sudo -u $LOCAL_USER smbutil view -N //$SERVER | grep Disk | sed 's/ *Disk *$//;s/ *$//g;s/^$//g' | while read MOUNT; | |
do | |
if [ -n "$MOUNT" ]; then | |
echo "Joining ${MOUNT}" | |
sudo -u $LOCAL_USER cd "${LOCAL_MOUNT}/${MOUNT}" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment