Skip to content

Instantly share code, notes, and snippets.

@afriza
Last active May 12, 2023 01:43
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 afriza/bacd11597ef1d83e41fa4dbbe9e716e2 to your computer and use it in GitHub Desktop.
Save afriza/bacd11597ef1d83e41fa4dbbe9e716e2 to your computer and use it in GitHub Desktop.
mount disk filesystem by LABEL from Linux and mount Samba shares from macOS via AppleScript
#!/bin/sh
domnt() {
local lbl="$1" mnt="$2"
if ! mount | grep -qF " $mnt " ; then
mkdir -p "$mnt"
if mount "LABEL=$lbl" "$mnt" ; then
echo "'LABEL=$lbl' has been mounted at '$mnt'"
fi
fi
}
while true; do
for lbl in label-one 'label two' "label three" ; do
domnt "$lbl" "/mnt/$lbl"
done
domnt 'MY DATA' /mnt/data
domnt 'ORICO_DISK_01' /mnt/disk1
sleep 15
done
# Linux Note:
# The order of filesystem types to be tried can be specified
# in /etc/filesystems
# It is better to combine with nofail option in /etc/fstab
#!/bin/sh
# mount SMB/CIFS from macOS using AppleScript.
# Ref: https://apple.stackexchange.com/questions/697/how-can-i-mount-an-smb-share-from-the-command-line#comment475611_303595
domnt() {
local loc="$1" mnt="$2"
if ! mount | grep -qF " $mnt " ; then
if timeout 7 osascript -e 'mount volume "'"$loc"'"' ; then
echo "'$loc' has been mounted at '$mnt'"
fi
fi
}
while true; do
domnt 'smb://user:pass@192.168.1.2/share1' /Volumes/share1
domnt 'smb://user:pass@192.168.1.2/share2' /Volumes/share2
sleep 15
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment