My solution for this is to use an Automator application, and a remounting script I wrote.
Part 1: Automating the Action
Using the Automator tool, I created a new
Application, to which I added in order:
Get Specified Servers action that gets my server (in my case, my raspberry pi)
Connect to Servers, which connects to the server I've gotten in the prior action. It should look like the below screenshot.
Part 2: Checking to see if the computer is connected to the server
This automates the action of connecting to the server, but it doesn't automate the reconnection process. For that I wrote a simple script that I run on a cron job that checks (every 10 seconds) if the computer has connected to the server, and if the drive is mounted like I expect it to be.
The script checks:
- If my computer can ping the server
- If my computer has already mounted the drive in
- If my computer can ping the server, but the drive is not mounted, it runs the Automator application.
if /sbin/ping -q -c 1 -W 1 <server ip goes here> >/dev/null; then
if [ ! -d "/Volumes/<your volume>" ]
Part 3: Checking every 10 seconds
The final part is in my
crontab, to run this script every minute:
* * * * * sh /usr/local/bin/remount/remount.sh
That runs it every minute - if you want it to run every 10 seconds you've got to add in multiple cron jobs to run the script at 10 second intervals, a la:
* * * * * sleep 10; sh /usr/local/bin/remount/remount.sh
* * * * * sleep 20; sh /usr/local/bin/remount/remount.sh
* * * * * sleep 30; sh /usr/local/bin/remount/remount.sh
* * * * * sleep 40; sh /usr/local/bin/remount/remount.sh
* * * * * sleep 60; sh /usr/local/bin/remount/remount.sh
Honestly there is probably an easier way to do this with just Automator - I'm using three things (crontab, a script, and an Automator App) together that I'm sure I could probably just use the Automator App script if I was just better at it!
That said, it does the job - when I open up my Macbook, and the drive is disconnected, this makes sure that the computer reconnects within 10 seconds if it can connect to the drive.