pages tagged perl
wiebel.org
http://wiebel.org//tag/perl/
wiebel.org
ikiwiki
2021-07-13T08:08:10Z
mysql
http://wiebel.org//linux/mysql/
2012-08-30T09:50:50Z
2012-04-12T01:42:57Z
<h1 id="mysql">mysql</h1>
<ul>
<li><p>Show Grants:</p>
<pre><code>mysql --skip-column-names -e "select distinct concat('show grants for''',user,'''@''',host,''';') as query from mysql.user" | \
mysql --skip-column-names | \
perl -ne 'next if m/(?:replica|root)/; s/$/;/; print; END {print "flush privileges;\n" }'
</code></pre>
<p>or use maatkit</p></li>
<li><p>Show Users:</p>
<pre><code>select user,host from mysql.user;
</code></pre></li>
</ul>
perl
http://wiebel.org//linux/perl/
2013-11-05T09:43:24Z
2012-04-12T01:42:57Z
<h1 id="perl">perl</h1>
<ul>
<li><p>Debugging:</p>
<pre><code>$| = 1;
Wenn diese Variable auf einen Wert ungleich 0 gesetzt wird, werden Ausgaben mit print nicht gepuffert, sondern erfolgen in dem Augenblick, wo die print-Anweisung interpretiert wird. Normalerweise puffert Perl Ausgaben, um sie dann blockweise auszugeben.
</code></pre></li>
<li><p>Base64 encoding (e.g. smtp auth)</p>
<pre><code>perl -MMIME::Base64 -e print encode_base64("text");
</code></pre></li>
</ul>
string manipulation
http://wiebel.org//linux/string_manipulation/
2021-07-13T08:08:10Z
2012-04-12T01:42:57Z
<h1 id="strings">strings</h1>
<ul>
<li><p>feature</p>
<pre><code> $ greedy match : 1#2#3#4 -> 1#2#3
$ non greedy match : 1#2#3#4 -> 1
$ last column : 1#2#3#4 -> 4
$ last 3 line
$ first 3 line
$ all but first 3 lines
$ all but last 3 lines
</code></pre></li>
<li><p>sed</p>
<pre><code> $ sed -e 's/\(.*\)#.*/\1/'
$ sed -e 's/\([^#]*\)#.*/\1/'
$ sed -e 's/.*#//'
</code></pre></li>
<li><p>perl</p>
<pre><code> $ perl -pe 's/(.*)#.*/\1/'
$ perl -pe 's/(.*?)#.*/\1/'a
$ perl -pe 's/.*#(.*)/\1/'
$ perl -lane 'print $F[-1]' (alt. last column)
</code></pre></li>
<li><p>ruby</p>
<pre><code> $ ruby -pe "gsub(/(.*)#.*/,'\1')"
$ ruby -pe "gsub(/(.*?)#.*/,'\1')"
$ ruby -pe "gsub(/.*#(.*)/,'\1')"
</code></pre></li>
<li><p>awk</p>
<pre><code> $ awk -F"#" '{{for (i=1; i<NF-1; i++) printf $i "#"} print $(NF-1)}'
$ awk -F"#" '{print $1}'
$ awk -F"#" '{print $NF}'
</code></pre></li>
<li><p>bash</p>
<pre><code> $ ???
$ ???
$ while IFS="#" read -r -a line; do
nb=${#line[@]}
echo ${line[$((nb - 1))]}
done
</code></pre></li>
<li><p>other tools</p>
<pre><code> $ cut -F# -f1
$ ???
$ rev | cut -F# -f1 | rev
</code></pre></li>
</ul>
mysql
http://wiebel.org//mysql/
2011-11-29T21:32:39Z
2011-11-24T00:26:41Z
<h1 id="showgrants:">Show Grants:</h1>
<pre><code>mysql --skip-column-names -e "select distinct concat('show grants for''',user,'''@''',host,''';') as query from mysql.user" | \
mysql --skip-column-names | \
perl -ne 'next if m/(?:monit|replica|root|ronie)/; s/$/;/; print; END {print "flush privileges;\n" }'}}
</code></pre>
<h1 id="showusers:">Show Users:</h1>
<pre><code>select user,host from mysql.user;
</code></pre>