My laptop hard drive died. I was upset only because there was data on my laptop that had not been moved over to my desktop. My desktop has time machine and is rsynced to several other drives and locations.
So I lost data. My own fault because I was not diligent in moving data off my laptop.
To make sure this did not happen again, I needed the ability to run a script when I open my laptop at home. But how?
- First, I thought about identifying being at home by my wireless SSID. That was okay, but what if I was connected by wire?
- Second, I thought about identifying home based on my subnet. Well, I could find myself on a network with the same range, and that could be bad.
- Then I found this link that showed some code on how to get the MAC address of the defined Default Gateway. Perfect.
MAC addresses should be unique. Therefore the BASH script should only run when I am on my home network.
Here is the BASH script to find the Default Gateway’s MAC address
GATEWAY=`netstat -rn | grep default | cut -c20-35` MACADDRESS=`arp -n $GATEWAY | cut -f4 -d' '`
Next step is to use this code when I open my Laptop lid.
Comments are closed.