Posted By

nathwill on 09/19/10


Tagged

event Bash script network


Versions (?)

Network Event Triggered Bash Script


 / Published in: Bash
 

URL: http://nathanewilliams.com/

updated...

  1. #!/bin/bash
  2. gateway=$(ip route show 0.0.0.0/0 | awk '{print $3}')
  3. mactest=$(arp -n -a $gateway | awk '{print $4}')
  4. targetmac="XX:XX:XX:XX:XX:XX"
  5. homeup="mount -t cifs -o username=USER,password=PASSWORD //SERVER/SHARE /mnt/remote"
  6. awayup="sshfs my.dyndns.tld:/path/to/share /mnt/remote"
  7. down="umount -l /mnt/remote"
  8. if [ $mactest==$targetmac ]
  9. 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. exit $?

Report this snippet  

You need to login to post a comment.