Mount Share Network Event Triggered Bash Script

What this script does is, check the gateway mac address to find out if you are within your lan or in a different place. If at home, mount a share as normal. If away, mount that share as a ssh file system.

 bash | 
 
 copy code |
?

01
#!/bin/bash
02
gateway=$(ip route show 0.0.0.0/0 | awk '{print $3}')
03
mactest=$(arp -n -a $gateway | awk '{print $4}')
04
targetmac="XX:XX:XX:XX:XX:XX"
05
homeup="mount -t cifs -o username=USER,password=PASSWORD //SERVER/SHARE /mnt/remote"
06
awayup="sshfs my.dyndns.tld:/path/to/share /mnt/remote"
07
down="umount -l /mnt/remote"
08
if [ $mactest==$targetmac ]
09
then
10
 case "$2" in
11
         up)
12
                $homeup
13
         ;;
14
         down)
15
                $down
16
         ;;
17
 esac
18
else
19
 case "$2" in
20
 up)
21
 $awayup
22
 ;;
23
 down)
24
 $down
25
 ;;
26
 esac
27
fi
28
29
30