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?

1 Answer 1

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  
3

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .