external-ip.bash 593 B

123456789101112131415161718192021222324252627
  1. #!/bin/bash
  2. ## Writes external ip into a html file
  3. PUBLIC_IP="$(dig +short myip.opendns.com @resolver1.opendns.com)"
  4. INDEX_FILE="/var/www/html/ip/index.html"
  5. if [ ! -z $1 ]
  6. then
  7. INDEX_FILE="${1}"
  8. fi
  9. if [ ! -f ${INDEX_FILE} ]
  10. then
  11. mkdir -p $(dirname ${INDEX_FILE})
  12. touch ${INDEX_FILE}
  13. fi
  14. echo '<!DOCTYPE HTML>' 1> ${INDEX_FILE}
  15. echo '<html>' 1>> ${INDEX_FILE}
  16. echo '<body>' 1>> ${INDEX_FILE}
  17. echo -n '<p>' 1>> ${INDEX_FILE}
  18. echo -n "${PUBLIC_IP}" 1>> ${INDEX_FILE}
  19. echo '</p>' 1>> ${INDEX_FILE}
  20. echo '</body>' 1>> ${INDEX_FILE}
  21. echo '</html>' 1>> ${INDEX_FILE}
  22. echo 1>> ${INDEX_FILE}