Page 1 of 1

Use custom script to check if server is reachable

PostPosted: Sat Nov 06, 2010 7:37 am
by admin
What's ?

This script is used when you select Ping server before trying to mount your volume under the Options panel.
Since version 1.3.4 it's possible to change the default ping script used by AutomountMaker for know if the host is reachable
or not before mount your volume.

Why change the default script ?

The default script is writing with Perl and some user (one for the moment, but...) tell me that my ping.pl doesn't work fine !
So, I added this feature to resolve this problem.

Your script must follow these rules
have an argument -h
must be invoked as: myping.sh -h example.com
return "YES" if server is reachable or "NO"

Example

This example is pre-installed into ./Contents/MacOS/, so you can use it without change it.
But you must set the hidden option (see How to install your new script)

Code: Select all
#!/bin/bash
#
# name
#   ping.sh
#
# usage
#   ping.sh -h example.com
#

args=`getopt h: $*`
if [ $? -ne 0 ]; then
  echo "Usage: $0 -h <yourhost>"
  exit 1
fi

host=""
set -- $args
for o
do case "$o" in
 -h) shift; host="$1"; shift;;
 --) shift; break;;
 esac
done

ping -n -c 1 $host >/dev/null 2>&1
if [ $? -eq 0 ]; then
 echo -n 'OK';
else
 echo -n 'KO';
fi


How to install your new script

    1) Quit AutomountMaker
    2) Select and choose Show Package Contents
    3) Open Contents/MacOS/ and copy your script on it,
    4) Open Terminal.app and enter this command (suppose that your script is called myping.sh):
    defaults write com.JMM.AutomountMaker AMScriptDictKey:PingScript myping.sh
    5) Relaunch AutomountMaker
Warning
    1) Test your script before use it with AutomountMaker
    2) Check that the current user can launch this script
mac:MacOS user$ ls -l myping.sh
-rwxr-xr-x 1 user admin 302 15 d?c 08:07 myping.sh


Nota
You can use ping.sh default alternative script pre-installed into ./Contents/MacOS/ (see Example)
defaults write com.JMM.AutomountMaker AMScriptDictKey:PingScript ping.sh