I've just completed a lengthy installation script that deploys a Ruby on Rails application unto web servers. At the end of this script, I'd like it to print something along the lines of: "Installation Complete. Access where is the server's public IP address.

I've found several free services that do this. I can successfully identify the server's IP address using either of the following:

  • dig @ns1.google.com -t txt o-o.myaddr.l.google.com +short
  • curl http://icanhazip.com
  • curl ident.me

I would like to identify the server's public IP address, save the result to a variable defined at the beginning of the shell script and print it to the end user at the end of installation.

marked as duplicate by Chris Down, jasonwryan, Stéphane Chazelas bash Mar 24 '15 at 18:15

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    You mean like ip=$(curl ident.me)? – Stéphane Chazelas Mar 24 '15 at 16:36
  • @StéphaneChazelas That did it. Thank you. If you provide that as an answer, I would mark it as an acceptable solution. – Ralph Mar 24 '15 at 17:35
  • I thought you'd also want "to print it to the end user", so some program like wall, talk, write, mesg, though to only one user, and across machine boundaries. (Well there's of course mail.) – Janis Mar 24 '15 at 18:32