Mounting volumes in the background

Hello I have been running this script in FileMaker Pro for years now and it has been quite reliable.

I now want to make my process more efficient. I am then starting to run filemaker script on the server than rather on the client.

However, for some of the filemaker scripts a NAS (Synology DS214+) called “FARAMIR” has the be mounted. Up to now there was no issues because those scripts ran on the client.

In running FileMaker server I only have to turn on my Mac mini and the server becomes remotely accessible to all clients. I do not have to logon onto an account and everything for filemaker server to be remotely accessible.

There is an exception, the NAS is not mounted.

Is there a way with an applescript for it to mount the NAS without having to log on? What about super user, would that be the way to go?

With regards!

Thanks


set cancellingscript to "NO"
set mountedFARAMIR to ""
repeat until mountedFARAMIR contains "MOUNTED"
	try
		set mountedERROR to "NO"
		set theping to (do shell script "ping -c 1 -t 1 192.10.5.63")
	on error
		display dialog "There was a problem connecting to the file server. FARAMIR does not seem to be available at this time. Verify if the server was started and try again" with icon stop buttons {"Cancel", "Keep trying..."}
		if button returned of result is "Cancel" then
			set cancellingscript to "YES"
		end if
		set mountedERROR to "YES"
		delay 5
	end try
	if mountedERROR is equal to "NO" or cancellingscript is equal to "YES" then
		set mountedFARAMIR to "MOUNTED"
	end if
end repeat
if cancellingscript is equal to "NO" then
	tell application "Finder"
		set mounted_disks to list disks
		--display dialog result as string
		if mounted_disks does not contain "Data" then
			try
				mount volume "afp://FARAMIR._afpovertcp._tcp.local/Data"
			on error errMSG number errorNumber
				display dialog ("There was a problem mounting FARAMIR/DATA : " & errorNumber as text) & ", please notify your system administrator"
				return
			end try
		end if
	end tell
	delay 3
	
end if

The button “Cancel” is reserved by the display dialog command to have special behaviour - immediately interrupting of the script. Therefore, you can’t get the result of the display dialog command when using exactly “Cancel”. To avoid this behaviour you can do 2 things: 1) set other name, for example: “cancel”, “CANCEL”, “canCel”, “Cancell” only not “Cancel”. 2) set display dialog into 1 second try block, trying to cat the “User cancelled” error.

Because your display dialog is already into one other try block, I advise you to use slightly different name. So as not to create unnecessary confusion.

With 2nd method you should do something like this:


set cancellingscript to "NO"
set mountedFARAMIR to ""
repeat until mountedFARAMIR contains "MOUNTED"
	try
		set mountedERROR to "NO"
		set theping to (do shell script "ping -c 1 -t 1 192.10.5.63")
	on error
		try
			display dialog "There was a problem connecting to the file server. FARAMIR does not seem to be available at this time. Verify if the server was started and try again" with icon stop buttons {"Cancel", "Keep trying..."}
		on error
			set cancellingscript to "YES"
		end try
		set mountedERROR to "YES"
		delay 5
	end try
	if mountedERROR is equal to "NO" or cancellingscript is equal to "YES" then
		set mountedFARAMIR to "MOUNTED"
	end if
end repeat
if cancellingscript is equal to "NO" then
	tell application "Finder"
		set mounted_disks to list disks
		--display dialog result as string
		if mounted_disks does not contain "Data" then
			try
				mount volume "afp://FARAMIR._afpovertcp._tcp.local/Data"
			on error errMSG number errorNumber
				display dialog ("There was a problem mounting FARAMIR/DATA : " & errorNumber as text) & ", please notify your system administrator"
				return
			end try
		end if
	end tell
	delay 3
	
end if

NOTE: I see a lot of redundant code here (several checks for the same condition, extra variables …). After solving the main problem, you should consider optimizing the code.

Updated script.
Removed unnecessary, added necessary. But I couldn’t go any further because the server is offline.


set aMessage to "There was a problem connecting to the file server.
FARAMIR does not seem to be available at this time.
Keep Trying will Verify if the server was started."
set {serverAvailable, buttonPressed} to {"NO", "NO"}

repeat while serverAvailable is "NO"
	try
		set serverAvailable to "YES"
		do shell script "ping -c 1 -t 1 192.10.5.63"
	on error
		if buttonPressed is "NO" then
			display dialog aMessage with icon stop buttons {"CANCEL", "KEEP TRYING..."}
			set buttonPressed to button returned of result
			if buttonPressed is "CANCEL" then
				display dialog "The script cancelled by the user"
				return
			end if
		end if
		set serverAvailable to "NO"
		delay 5
	end try
end repeat

tell application "Finder"
	set mounted_disks to list disks
	--display dialog result as string
	if mounted_disks does not contain "Data" then
		try
			mount volume "afp://FARAMIR._afpovertcp._tcp.local/Data"
		on error errMSG number errorNumber
			display dialog ("There was a problem mounting FARAMIR/DATA : " & errorNumber as text) & ", please notify your system administrator"
			return
		end try
	end if
end tell

Thanks KniazidisR for your reply.

I am sorry for the confusion. The issue here is more the ability to run the script in the background. I.e without logging onto a user account. In running the script in the background there are no user interaction being possible.

I’ve just removed from the script all lines where there was some user interaction. From the script the NAS is found (ping) and Data can be mounted. This implies there would be a sequence in the order the computer and the NAS is turned on.

First, I would start the NAS and wait until the light is no longer flashing;
Two, I would then start the MacMini without logging in.

Then the script to mount the external drive is to be performed in the background.

Is there a way with an applescript for it to mount the NAS without having to log on? Is there a way for the applescript down below to be run in the background? What about super user, would that be the way to go?

try
	do shell script "ping -c 1 -t 1 192.10.5.63"
on error
	return
end try

tell application "Finder"
	set mounted_disks to list disks
	if mounted_disks does not contain "Data" then
		try
			mount volume "afp://FARAMIR._afpovertcp._tcp.local/Data"
		on error
			return
		end try
	end if
end tell

Thanks Fredrik71.

Wow, this is exactly what I was looking for. This is greatly appreciated, I will be testing it on next week.

Also I did not about apple afp vs smb. I have been using the Go + Connect to server command and they only offer afp as a choice. Maybe it’s because I am using Mojave.

I will also look into this.

With regards!

Hello Fredrik71

I am trying to understand the command line.

On my system there is no Share folder but there is a Shared folder. Would that be the same ?

What does the MyDrive stand/used for ?

In looking in the old afp command and the smb command you are recommending I would then substitue the NAS_DRIVE with FARAMIR and /directory_path with /Data

What do you think in adding : soft,noowners,noatime,nosuid part of the -fstype

The command would then look like this, :

does it make sense? At the moment I really do not understand the statement “/Users/Shared/MyDrive”

Also in going within the etc folder, I’ve noticed there is no « auto_smb » file.

Should I add in the auto_master the following ?

Network Shares

/- auto_smb -nosuid,noowners

and then create the auto_smb file with the command line -fstype=smbfs,soft… ?

With regards!

Thanks!

MANY THANKS for your help, it is GREATLY appreciated.

On my NAS named FARAMIR, the directory structure is the following:
/Data/ZVinformatique/CompétitionCourante/01/mp4files.mp4
/WebMediaFile/WebDAV/clip/mp4files.mp4
/CompétitionPrécédente/mp4files.mp4

When accessing the files I always refer to :
/Volumes/Data/…
/Volumes/WebMediaFile/…
/Volumes/CompétitionPrécédente/…

For my programs to work I need whatever is found after Volumes stays the same. Doing the following would that make sense.

Thanks again.

I had the same issue you had with the emoj, I clicked “never show smile as icons for this post”

Without the option

the [YourDirectory] should they be different one for /Data and the other one for /CompétitionPrécédente. My guess would be that they have to be different. Am I correct?

With the option

Here are the auto_master and the auto_smb files stored in /etc

/etc/auto_master

/etc/auto_smb

Is there a way to know if those are being executed?
Is there a way to test it without having to restart the macmini?

Where could I find more about this type pf programming?

Thanks!

Thanks again!

I am a beginner in this type of scripting. I know this is not applescript, neither I believe it is shell scripting. How do we call this type of scripting?

As per the log,

I’ve looked into Console + System Reports, User Reports, system.log, /Library/Logs, /var/log and do not find any statement about mounting successfully the NAS or not. I did not find anything there?

I did cmd + v upon startup and the log started to display. It went so fast that it was difficult to see if auto_smb was executed. I then logged in under my account and under terminal typed the following “sudo dmesg” command. I’ve copied and pasted the log in a textedit document. Doing a search on the command line declared in auto_smb I did not find anything.

In looking at the two posted links in more details I saw instructions on “How to configure your MAC to automatically mount an SMD share as needed”. Within the instructions there is a bunch of sudo command. I did not execute any of the sudo command. When updating the auto_master and creating the auto_smb file I’ve :

1 - went directly into the /etc folder;
2 - copied /etc/auto_master and pasted it in desktop;
3 - textedit auto_master to add the auto_smb statement;
4 - pasted another copy of auto_master, renamed auto_master to auto_smb;
5 - recorded in auto_smb the mount statement;
6 - pasted/replaced the desktop auto_master in /etc;
7 - pasted the desktop auto_smb in /etc.

Should I’ve been using the sudo command instead?

MANY THANKS AGAIN!

  1. Your steps above is the 1st manual way to change etc contents (editing it in the TextEdit).
  2. Other manual way is using Terminal window + sudo.
  3. 3rd way. To do all at the place using AppleScript, instead of sudo you should use with administrator privileges statement.

For example, instead of $ sudo touch /etc/auto_afp (in Teminal window), you should use this:

do shell script "touch /etc/auto_afp" with administrator privileges

Please note, I sincerely appreciate your help. This is difficulty for me because I trying to do something I require but for which I am not familiar with this scripting.

Confirmed!

I still have the original. In this link http://www.csd.uwo.ca/~amulder/HowTo/smb-mounts-auto/

$ sudo vi /etc/auto_master

Add the line “/- auto_smb” to that file.
$ sudo touch /etc/auto_smb
$ sudo vi /etc/auto_smb
$ sudo chmod 600 /etc/auto_smb

To me performing

was the same then doing

Peforming

was the same than doing

I do not know what the

is doing.

Then, if better I could go back to the original auto_master and perform all of the sudo commands as describe in the link http://www.csd.uwo.ca/~amulder/HowTo/smb-mounts-auto/

Do you recommend for me to start all over and do the sudo commands as described in the link above?

_

What type of scripting is being used within an auto_master?

I believe this is not a bash neither a shell script.
I believe this is not an applescript.

What is it then?

THANKS!

Thanks again!

Do not worry, I did all of those research and I have been watching YouTube videos like crazy and still looking for how this script is being called. I know FORTRAN, COBOL, PL/1, Basic, RPG, Assembler, Esri Info, FileMaker Pro, SQL, AML and other programming languages.

I want to be able to test this script but again I am still trying to find what programming, scripting language this is. Why ? Because I want to understand better what I am dealing with.

Doing a google search on /etc means was done three data ago and still.
Doing google search on keyword, I am doing.
I did google search on auto_master example
I did google search on auto_smb examples
I’ve opened and tried to understand other script found in /etc and /etc subfolders…
Doing those google search I´ve found bash and shell script are pretty much the same they both have to start with #! and they both need to be made executable with a chmod +x executable
I’ve looked at https://osxdaily.com/2007/03/30/mac-os-x-directory-structure-explained/ and found out etc meant “Machine local system configuration, holds administrative, configuration, and other system files”.

I will still continue doing google search. If I would find this is cobol programming I would than get a cobol programming manual.

I’ve started to look at freebsd

Lately I’ve looked it was a daemon scripting and its not. Unfortunately, I am still asking myself “What is it then?“