Blog Entries tagged "command-line"

SSH Tunnels into Production Rails Database

<p>Today I needed to access a production database for my Rails app directly using a GUI application on my mac, so I figured out that this can be done by creating an SSH tunnel like so:</p> <div class="highlight"><pre class="highlight shell"><code>ssh <span class="nt">-Ng</span> <span class="nt">-L</span> &lt;local-port&gt;:&lt;remote-host&gt;:&lt;remote-port&gt; &lt;user&gt;@&lt;remote-host&gt; ssh <span class="nt">-Ng</span> <span class="nt">-L</span> 3307: adam@ </code></pre></div> <p>And then, in your Rails app, update the database.yml as if you were connecting to a local database, but specify the proper database name.</p> <div class="highlight"><pre class="highlight yaml"><code><span class="na">development</span><span class="pi">:</span> <span class="na">adapter</span><span class="pi">:</span> <span class="s">mysql2</span> <span class="na">database</span><span class="pi">:</span> <span class="s">myapp_production</span> <span class="na">host</span><span class="pi">:</span> <span class="s"></span> <span class="na">port</span><span class="pi">:</span> <span class="m">3307</span> <span class="na">username</span><span class="pi">:</span> <span class="s">root</span> <span class="na">password</span></code></pre></div>


Lookup IP Address & Location via the Command Line

<p>With <a href=""></a>, you can lookup your external IP Address and Location Information using a simple curl command. You can use it like so:</p> <div class="highlight"><pre class="highlight shell"><code><span class="nv">$ </span>curl <span class="o">{</span> <span class="s2">"ip"</span>: <span class="s2">""</span>, <span class="s2">"ip_decimal"</span>: 1612409628, <span class="s2">"country"</span>: <span class="s2">"United States"</span>, <span class="s2">"country_iso"</span>: <span class="s2">"US"</span>, <span class="s2">"city"</span>: <span class="s2">"Columbus"</span>, <span class="s2">"hostname"</span>: <span class="s2">""</span> <span class="o">}</span> <span class="nv">$ </span>curl Columbus <span class="nv">$ </span>curl United States </code></pre></div>