2

I want to connect to a network share and I want the connection to remain active after logout. I tried:

$ echo "/-      auto_smb        -nosuid,noowners,nofail
        /-      auto_afp        -nobrowse,nosuid" >> /etc/auto_master
$ echo "/System/Volumes/Data/mount/Test2 -fstype=smbfs,soft,noowners,nosuid,rw ://$username:$password@server/share" >> /etc/auto_smb
$ automount -cv

My username and password have special characters so I tried escaping them and replacing them with URL encoding, but it did not work. What am I doing wrong?

jaume
  • 15,010

1 Answers1

1

This is the article that i used https://useyourloaf.com/blog/using-the-mac-os-x-automounter/ and my code:

networkPath
persistent="true"
username
password

function debugEcho () { if (true) then echo -e $1 fi }

shareName=${networkPath##/} debugEcho "$shareName" userPersistent=$username userPersistent=$(echo "$username" | tr "\" ";") if [[ $username == "@"* ]]; then OIFS=$IFS IFS=@ set -- $username user=$1 domain=$2 debugEcho "$user $domain" userPersistent="$domain;$user" IFS=$OIFS debugEcho "$userPersistent" fi

username=${username//@/"%40"} debugEcho $username shareName="TEST7"

if [[ "$persistent" == "true" ]]; then mkdir -p /System/Volumes/Data/mnt LINE="/System/Volumes/Data/mnt/Resources auto_resources" FILE='/etc/auto_master' grep -qF -- "$LINE" "$FILE" || echo "$LINE" >> "$FILE" touch /etc/auto_resources LINE="$shareName -fstype=smbfs ://$userPersistent:$password@$networkPath" FILE='/etc/auto_resources' grep -qF -- "$LINE" "$FILE" || echo "$LINE" >> "$FILE" automount -cv open "/System/Volumes/Data/mnt/Resources/" path1="/System/Volumes/Data/mnt/Resources/" path2="~/Desktop/" debugEcho "$path1" ln -s $path1 $path2

else open "smb://$username:$password@$networkPath"

fi

  • I don't know about AFP, but I found SMB much simpler than the above: https://apple.stackexchange.com/questions/697/how-can-i-mount-an-smb-share-from-the-command-line/247885#247885 – WGroleau Jul 27 '20 at 16:42
  • It would be important to note that AFP's been deprecated for some time now: https://eclecticlight.co/2019/12/09/can-you-still-use-afp-sharing/. SMB would be a better option. – Allan Jul 27 '20 at 18:40
  • this solution is for smb. @WGroleau i tried that solution but the paths are different since Catalina. – Georgiana Untaru Jul 28 '20 at 11:07