Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #!/bin/bash
  2. # this script and "currentIP.txt" must be in the same directory
  3. # run "(hostname -I) > currentIP.txt" in bash before running this script the first time
  4. ip_rightNow=$(hostname -I)
  5.  
  6. ip_prev=$(cat currentIP.txt)
  7.  
  8. if [[ "$ip_rightNow" != "$ip_prev" ]]; then
  9. echo $ip_rightNow > currentIP.txt
  10. scp currentIP.txt user@XXX.XXX.XXX.XXX:/path/to/directory
  11. fi
  12.  
  13. # above depends on ssh key authentication (no passphrase on key)
  14. # can add this to crontab to run every Y minutes with:
  15. # */Y * * * * /path/to/updateIP.sh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement