snipt

Ctrl+h for KB shortcuts

Bash

Completely flush iptables

1
2
3
4
5
6
7
8
# Source: https://serverfault.com/a/200642/88004

iptables-save | awk '/^[*]/ { print $1 } 
                     /^:[A-Z]+ [^-]/ { print $1 " ACCEPT" ; }
                     /COMMIT/ { print $0; }' | iptables-restore

# "All policies will be reset to ACCEPT as well as flushing every table in current use.
#     All chains other than the built in chains will no longer exist."
https://snipt.net/embed/4255fdb928925407842a67e46c64fc17/
/raw/4255fdb928925407842a67e46c64fc17/
4255fdb928925407842a67e46c64fc17
bash
Bash
8
2019-06-21T23:55:43
True
False
False
/api/public/snipt/147274/
completely-flush-iptables
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1"># Source: https://serverfault.com/a/200642/88004</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>iptables-save <span class="p">|</span> awk <span class="s1">&#39;/^[*]/ { print $1 } </span> </span><span id="L-4"><a name="L-4"></a><span class="s1"> /^:[A-Z]+ [^-]/ { print $1 &quot; ACCEPT&quot; ; }</span> </span><span id="L-5"><a name="L-5"></a><span class="s1"> /COMMIT/ { print $0; }&#39;</span> <span class="p">|</span> iptables-restore </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a><span class="c1"># &quot;All policies will be reset to ACCEPT as well as flushing every table in current use.</span> </span><span id="L-8"><a name="L-8"></a><span class="c1"># All chains other than the built in chains will no longer exist.&quot;</span> </span></pre></div> </td></tr></table>
iptables

Bash

Add app db and user to postgresql

sudo -u postgres createuser -DAP username
sudo -u postgres createdb -O username dbname
https://snipt.net/embed/f1970057c0ae2557fa393a9fee92adf2/
/raw/f1970057c0ae2557fa393a9fee92adf2/
f1970057c0ae2557fa393a9fee92adf2
bash
Bash
2
2019-05-22T12:10:45
True
False
False
/api/public/snipt/141027/
add-app-db-and-user-to-postgresql
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>sudo -u postgres createuser -DAP username </span><span id="L-2"><a name="L-2"></a>sudo -u postgres createdb -O username dbname </span></pre></div> </td></tr></table>

Bash

Grepping large files; fast_grep

1
2
3
4
5
6
7
#!/bin/bash

# Info:  http://www.inmotionhosting.com/support/website/ssh/speed-up-grep-searches-with-lc-all
# LC_ALL=C sets locale to ASCII
# fgrep wraps "grep -F" -- search for plain strings (no regex)

alias fast_grep='LC_ALL=C fgrep --color'
https://snipt.net/embed/342fae09c5198ee93ea599ce9304985a/
/raw/342fae09c5198ee93ea599ce9304985a/
342fae09c5198ee93ea599ce9304985a
bash
Bash
7
2019-06-21T16:58:40
True
False
False
Aug 07, 2015 at 09:35 AM
/api/public/snipt/140578/
grepping-large-files-fast_grep
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="ch">#!/bin/bash</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="c1"># Info: http://www.inmotionhosting.com/support/website/ssh/speed-up-grep-searches-with-lc-all</span> </span><span id="L-4"><a name="L-4"></a><span class="c1"># LC_ALL=C sets locale to ASCII</span> </span><span id="L-5"><a name="L-5"></a><span class="c1"># fgrep wraps &quot;grep -F&quot; -- search for plain strings (no regex)</span> </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a><span class="nb">alias</span> <span class="nv">fast_grep</span><span class="o">=</span><span class="s1">&#39;LC_ALL=C fgrep --color&#39;</span> </span></pre></div> </td></tr></table>
grep

Bash

Extract my IP from ipchicken.com

1
2
3
4
5
#!/bin/sh

# Obsolete:  just curl icanhazip.com

curl -s ipchicken.com | perl -ne 'print m/\b(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\b/g'
https://snipt.net/embed/b12c691e26598a6b3f574d91fc325c26/
/raw/b12c691e26598a6b3f574d91fc325c26/
b12c691e26598a6b3f574d91fc325c26
bash
Bash
5
2019-06-17T17:49:03
True
False
False
Dec 10, 2015 at 09:58 AM
/api/public/snipt/140116/
extract-my-ip-from-ipchickencom-e75948cf
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="ch">#!/bin/sh</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="c1"># Obsolete: just curl icanhazip.com</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a>curl -s ipchicken.com <span class="p">|</span> perl -ne <span class="s1">&#39;print m/\b(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\b/g&#39;</span> </span></pre></div> </td></tr></table>

Bash

Subversion rollback

1
2
3
svn update
svn merge -r HEAD:140 .
svn commit -m "Rolled back to r140"
https://snipt.net/embed/d6e03c58efa5d501c4af47e2778982b0/
/raw/d6e03c58efa5d501c4af47e2778982b0/
d6e03c58efa5d501c4af47e2778982b0
bash
Bash
3
2019-06-24T15:00:50
True
False
False
/api/public/snipt/139624/
subversion-rollback-b965a57b
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>svn update </span><span id="L-2"><a name="L-2"></a>svn merge -r HEAD:140 . </span><span id="L-3"><a name="L-3"></a>svn commit -m <span class="s2">&quot;Rolled back to r140&quot;</span> </span></pre></div> </td></tr></table>
svn