<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Pario TechnoBlob &#187; awk</title>
	<atom:link href="http://pario.no/tag/awk/feed/" rel="self" type="application/rss+xml" />
	<link>http://pario.no</link>
	<description>A cronological documentation test project, nothing serious, really!</description>
	<lastBuildDate>Wed, 14 Jul 2010 12:12:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>My 10 most used linux commands</title>
		<link>http://pario.no/2008/02/25/my-10-most-used-linux-commands/</link>
		<comments>http://pario.no/2008/02/25/my-10-most-used-linux-commands/#comments</comments>
		<pubDate>Mon, 25 Feb 2008 07:49:40 +0000</pubDate>
		<dc:creator>Hans-Henry Jakobsen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[count]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[head]]></category>
		<category><![CDATA[nl]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://pario.no/2008/02/25/my-10-most-used-linux-commands/</guid>
		<description><![CDATA[This is a oneliner bash command to determine my 10 most used linux commands according to my history file history &#124; awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' &#124; grep -v "./" &#124; column -c3 -s " " -t &#124; sort -nr &#124; nl &#124; head -n10 The [...]]]></description>
			<content:encoded><![CDATA[<p>This is a oneliner bash command to determine my 10 most used linux commands according to my history file</p>
<pre>history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl |  head -n10</pre>
<p>The result</p>
<pre>
     1  188  37.6%  vi
     2  38   7.6%   ls
     3  24   4.8%   cat
     4  22   4.4%   apt-get
     5  12   2.4%   date
     6  11   2.2%   tail
     7  11   2.2%   cd
     8  10   2%     rm
     9  10   2%     man
    10  9    1.8%   basename</pre>
<p>It looks like i use <strong>vim</strong> a lot on my home server. You should try it yourself and see what commands you use the most.</p>
<p>Source: <a href="http://linux.byexamples.com/archives/332/what-is-your-10-common-linux-commands/">http://linux.byexamples.com</a></p>
<script type="text/javascript">var wordpress_toolbar_urls = ["http:\/\/linux.byexamples.com\/archives\/332\/what-is-your-10-common-linux-commands\/"];var wordpress_toolbar_url = "http://pario.no/wp-content/plugins/wordpress-toolbar/toolbar.php";var wordpress_toolbar_oinw = "n";var wordpress_toolbar_hash = "aHR0cDovL3BhcmlvLm5vLzIwMDgvMDIvMjUvbXktMTAtbW9zdC11c2VkLWxpbnV4LWNvbW1hbmRzLzx3cHRiPk15IDEwIG1vc3QgdXNlZCBsaW51eCBjb21tYW5kczx3cHRiPmh0dHA6Ly9wYXJpby5ubzx3cHRiPlBhcmlvIFRlY2hub0Jsb2I%3D";</script>]]></content:encoded>
			<wfw:commentRss>http://pario.no/2008/02/25/my-10-most-used-linux-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache web connections pr hour</title>
		<link>http://pario.no/2008/02/21/apache-web-connections-pr-hour/</link>
		<comments>http://pario.no/2008/02/21/apache-web-connections-pr-hour/#comments</comments>
		<pubDate>Thu, 21 Feb 2008 22:26:15 +0000</pubDate>
		<dc:creator>Hans-Henry Jakobsen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[sed]]></category>

		<guid isPermaLink="false">http://pario.no/2008/02/21/428/</guid>
		<description><![CDATA[This is a bash oneliner to show Apache web connections pr hour. It lists up the IPs that has accessed your webserver and the amount og accesses. # cat /var/log/apache2/access_log_pario.no &#124; grep "21/Jan/2008:.." &#124; awk {' print $4":"$1 '} &#124; sed 's/\[//g' &#124; awk -F : {' print $1":"$2"\t\t"$5 '} &#124; sort &#124; uniq -c [...]]]></description>
			<content:encoded><![CDATA[<p>This is a bash oneliner to show Apache web connections pr hour. It lists up the IPs that has accessed your webserver and the amount og accesses.</p>
<pre>
# cat /var/log/apache2/access_log_pario.no | grep "21/Jan/2008:.." | awk {' print $4":"$1 '} | sed 's/\[//g' | awk -F : {' print $1":"$2"\t\t"$5 '} | sort | uniq -c</pre>
<p>Example output</p>
<pre>
37 21/Jan/2008:00          192.168.0.10</pre>
<p>This shows that I had 37 hits from 00:00 &#8211; 01:00 in 20th February 2008.</p>
<script type="text/javascript">var wordpress_toolbar_urls = [];var wordpress_toolbar_url = "http://pario.no/wp-content/plugins/wordpress-toolbar/toolbar.php";var wordpress_toolbar_oinw = "n";var wordpress_toolbar_hash = "aHR0cDovL3BhcmlvLm5vLzIwMDgvMDIvMjEvYXBhY2hlLXdlYi1jb25uZWN0aW9ucy1wci1ob3VyLzx3cHRiPkFwYWNoZSB3ZWIgY29ubmVjdGlvbnMgcHIgaG91cjx3cHRiPmh0dHA6Ly9wYXJpby5ubzx3cHRiPlBhcmlvIFRlY2hub0Jsb2I%3D";</script>]]></content:encoded>
			<wfw:commentRss>http://pario.no/2008/02/21/apache-web-connections-pr-hour/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Allow NFS through iptables</title>
		<link>http://pario.no/2007/12/20/allow-nfs-through-iptables/</link>
		<comments>http://pario.no/2007/12/20/allow-nfs-through-iptables/#comments</comments>
		<pubDate>Thu, 20 Dec 2007 09:50:41 +0000</pubDate>
		<dc:creator>Hans-Henry Jakobsen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[nmap]]></category>
		<category><![CDATA[rpcinfo]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://pario.no/2007/12/20/allow-nfs-through-iptables/</guid>
		<description><![CDATA[This is one way to determine the ports needed to open in your iptables rules to get NFS to work properly. First we need to determine the ports NFS uses rpcinfo -p &#124; awk -F " " '{print $3 ", " $4 ", " $5}' &#124; sort &#124; uniq Notice! Since portmap assigns ports on [...]]]></description>
			<content:encoded><![CDATA[<p>This is one way to determine the ports needed to open in your iptables rules to get NFS to work properly. First we need to determine the ports NFS uses</p>
<pre>
rpcinfo -p | awk -F " " '{print $3 ", " $4 ", " $5}' | sort | uniq</pre>
<p><strong>Notice!</strong><br />
Since portmap assigns ports on random this example is only valid as long as you don&#8217;t restart your NFS.</p>
<p>On my system, a RedHat Enterprise Linux WS 4, the result was</p>
<pre>
proto, port,
tcp, 111, portmapper
tcp, 2049, nfs
tcp, 32771, nlockmgr
tcp, 768, rquotad
tcp, 782, mountd
udp, 111, portmapper
udp, 2049, nfs
udp, 32768, nlockmgr
udp, 765, rquotad
udp, 779, mountd</pre>
<p>This gave me  a nice overview of protocols (tcp/udp) and ports used.</p>
<p>Now the rules</p>
<pre>
iptables -A RH-Firewall-1-INPUT -s 192.168.0.0/255.255.255.0 -i eth0 -p tcp -m state --state NEW -m multiport --dports 111,2049,32771,768,782 -j ACCEPT
iptables -A RH-Firewall-1-INPUT -s 192.168.0.0/255.255.255.0 -i eth0 -p udp -m state --state NEW -m multiport --dports 111,2049,32768,765,779 -j ACCEPT</pre>
<p>You see that the multiport statement is just like the result of my rpcinfo command above.</p>
<p>Remember to save your new rules, othervise they will disappear the next time the iptables rules are being loaded.</p>
<p>In addition to this rule you should add the <a href="http://pario.no/2007/05/08/ssh-dictionary-attack-prevention-with-iptables/">iptables rule for ssh access</a> I wrote about earlier.</p>
<p>Another way to determine the ports</p>
<pre>
nmap -sC -p 111 localhost</pre>
<p><strong>Notice!</strong><br />
This solution won&#8217;t work after a reboot of the server since NFS changes ports. One way to overcome this problem is to follow the instructions in a newer post I&#8217;ve made about <a href="http://pario.no/2008/01/15/allow-nfs-through-iptables-on-a-redhat-system/">RedHat and NFS</a>.</p>
<script type="text/javascript">var wordpress_toolbar_urls = [];var wordpress_toolbar_url = "http://pario.no/wp-content/plugins/wordpress-toolbar/toolbar.php";var wordpress_toolbar_oinw = "n";var wordpress_toolbar_hash = "aHR0cDovL3BhcmlvLm5vLzIwMDcvMTIvMjAvYWxsb3ctbmZzLXRocm91Z2gtaXB0YWJsZXMvPHdwdGI%2BQWxsb3cgTkZTIHRocm91Z2ggaXB0YWJsZXM8d3B0Yj5odHRwOi8vcGFyaW8ubm88d3B0Yj5QYXJpbyBUZWNobm9CbG9i";</script>]]></content:encoded>
			<wfw:commentRss>http://pario.no/2007/12/20/allow-nfs-through-iptables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adjust images to a digital frame (480&#215;234 pixels)</title>
		<link>http://pario.no/2007/11/25/adjust-images-to-a-digital-frame-480x234-pixels/</link>
		<comments>http://pario.no/2007/11/25/adjust-images-to-a-digital-frame-480x234-pixels/#comments</comments>
		<pubDate>Sun, 25 Nov 2007 12:03:38 +0000</pubDate>
		<dc:creator>Hans-Henry Jakobsen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Photo etc]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[montage]]></category>
		<category><![CDATA[od]]></category>

		<guid isPermaLink="false">http://pario.no/2007/11/25/adjust-images-to-a-digital-frame-480x234-pixels/</guid>
		<description><![CDATA[This bash script adjusts images to fit in a digital frame with a resolution of 480&#215;234 pixels however by using the size 832&#215;468 pictures are displayed sharper on some frames. Normally, narrower pictures will have black borders at both sides when displayed. but this script makes the border color the average of the picture. The [...]]]></description>
			<content:encoded><![CDATA[<p>This bash script adjusts images to fit in a digital frame with a resolution of 480&#215;234 pixels however by using the size 832&#215;468 pictures are displayed sharper on some frames.  Normally, narrower pictures will have black borders at both sides when displayed. but this script makes the border color the average of the picture.</p>
<p>The following linux tools are used in the script: convert and montage, bash, od and awk. od is part of the textutils package in Debian.</p>
<pre>
#!/bin/bash
# current directory contains source JPG files
# $DESTINATION is where the prepared JPG files are stored
# $TEMP is a temporary directory
TEMP=TEMP
DESTINATION=DESTINATION
GEO=832x468 # geometry of target JPG files and resize value

for FILE in *.JPG
do
convert -resize 1x1 "$FILE" "$TEMP/1x1.bmp"
od -A n -j 54 -t u1 "$TEMP/1x1.bmp" | awk -v f="$FILE" -v des="$DESTINATION/" -v geo="$GEO" '
{
print "montage -geometry", geo, "-resize", geo, "-background rgb\\(" $3 \
"," $2 "," $1 "\\) \"" f "\" \"" des f "\"";
exit;
}'

done | sh -x</pre>
<p>Source: <a href="http://groups.google.com/group/comp.graphics.misc/browse_thread/thread/312e98382b9b4102">comp.graphics.misc</a></p>
<script type="text/javascript">var wordpress_toolbar_urls = ["http:\/\/groups.google.com\/group\/comp.graphics.misc\/browse_thread\/thread\/312e98382b9b4102"];var wordpress_toolbar_url = "http://pario.no/wp-content/plugins/wordpress-toolbar/toolbar.php";var wordpress_toolbar_oinw = "n";var wordpress_toolbar_hash = "aHR0cDovL3BhcmlvLm5vLzIwMDcvMTEvMjUvYWRqdXN0LWltYWdlcy10by1hLWRpZ2l0YWwtZnJhbWUtNDgweDIzNC1waXhlbHMvPHdwdGI%2BQWRqdXN0IGltYWdlcyB0byBhIGRpZ2l0YWwgZnJhbWUgKDQ4MCYjMjE1OzIzNCBwaXhlbHMpPHdwdGI%2BaHR0cDovL3BhcmlvLm5vPHdwdGI%2BUGFyaW8gVGVjaG5vQmxvYg%3D%3D";</script>]]></content:encoded>
			<wfw:commentRss>http://pario.no/2007/11/25/adjust-images-to-a-digital-frame-480x234-pixels/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nslookup-scan of IP-range/subnet</title>
		<link>http://pario.no/2007/09/04/nslookup-scan-of-ip-rangesubnet/</link>
		<comments>http://pario.no/2007/09/04/nslookup-scan-of-ip-rangesubnet/#comments</comments>
		<pubDate>Tue, 04 Sep 2007 09:57:45 +0000</pubDate>
		<dc:creator>Hans-Henry Jakobsen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[nslookup]]></category>
		<category><![CDATA[sed]]></category>

		<guid isPermaLink="false">http://hhj.no/wordpress/2007/09/04/nslookup-scan-av-ip-rangesubnett/</guid>
		<description><![CDATA[#!/bin/bash # nslookup-scan of IP-range # It's possible to add more networks separated with space NETS="192.168.0" IPRange="1 254" for NET in $NETS; do for n in $(seq $IPRange); do ADDR=${NET}.${n} echo "${ADDR},`nslookup ${ADDR} &#124; awk -F "=" '{ print $2 }'&#124;sed 's/^[ t]*//' &#124; sed '/^$/d' &#124; &#124;sed 's/.$//'`" done done Result 192.168.0.1,cba.infra.no 192.168.0.2,bca.infra.no 192.168.0.3,abc.infra.no [...]]]></description>
			<content:encoded><![CDATA[<pre>
#!/bin/bash
# nslookup-scan of IP-range

# It's possible to add more networks separated with space
NETS="192.168.0"

IPRange="1 254"
for NET in $NETS; do
  for n in $(seq $IPRange); do
        ADDR=${NET}.${n}
        echo "${ADDR},`nslookup ${ADDR} | awk -F "=" '{ print $2 }'|sed 's/^[ t]*//' | sed '/^$/d' | |sed 's/.$//'`"
  done
done</pre>
<p><strong>Result</strong></p>
<pre>
192.168.0.1,cba.infra.no
192.168.0.2,bca.infra.no
192.168.0.3,abc.infra.no
192.168.0.4,
192.168.0.5,
192.168.0.6,
192.168.0.7,
192.168.0.8,</pre>
<script type="text/javascript">var wordpress_toolbar_urls = [];var wordpress_toolbar_url = "http://pario.no/wp-content/plugins/wordpress-toolbar/toolbar.php";var wordpress_toolbar_oinw = "n";var wordpress_toolbar_hash = "aHR0cDovL3BhcmlvLm5vLzIwMDcvMDkvMDQvbnNsb29rdXAtc2Nhbi1vZi1pcC1yYW5nZXN1Ym5ldC88d3B0Yj5uc2xvb2t1cC1zY2FuIG9mIElQLXJhbmdlL3N1Ym5ldDx3cHRiPmh0dHA6Ly9wYXJpby5ubzx3cHRiPlBhcmlvIFRlY2hub0Jsb2I%3D";</script>]]></content:encoded>
			<wfw:commentRss>http://pario.no/2007/09/04/nslookup-scan-of-ip-rangesubnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
