<?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>/root.eu</title>
	<atom:link href="http://slashroot.eu/feed/" rel="self" type="application/rss+xml" />
	<link>http://slashroot.eu</link>
	<description>Notepad of geeky sysadmin</description>
	<lastBuildDate>Fri, 11 Jun 2010 19:52:09 +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>Permission denied when mounting nfs share</title>
		<link>http://slashroot.eu/2010/06/10/permission-denied-when-mounting-nfs-share/</link>
		<comments>http://slashroot.eu/2010/06/10/permission-denied-when-mounting-nfs-share/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 08:40:26 +0000</pubDate>
		<dc:creator>root</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[nfs]]></category>

		<guid isPermaLink="false">http://slashroot.eu/?p=205</guid>
		<description><![CDATA[I had a problem with nfs share today. I couldn`t mount it on remote server. It failed with the following error: mount: xxx:/yyy failed, reason given by server: Permission denied I checked the configuration dozens of times &#8211; it was good, and the nfs server granted access to the share. The following info appeared in [...]]]></description>
			<content:encoded><![CDATA[<p>I had a problem with nfs share today. I couldn`t mount it on remote server. It failed with the following error:</p>
<p><code><br />
mount: xxx:/yyy failed, reason given by server: Permission denied<br />
</code></p>
<p>I checked the configuration dozens of times &#8211; it was good, and the nfs server granted access to the share. The following info appeared in logs:</p>
<p><code><br />
.. authenticated mount request from 1.1.1.1 for /yyy<br />
</code></p>
<p>So everything looked ok, but it didn`t work. The problem was a pseudo filesystem <b>nfsd</b> which should be mounted in <b>/proc/fs/nfsd</b>, but for some reason it wasn`t. I`ve added the following entry to <b>/etc/fstab</b></p>
<p><code><br />
none                    /proc/fs/nfsd           nfsd    defaults        0 0<br />
</code></p>
<p></br></p>
<p>and mounted it:</p>
<p><code><br />
mount /proc/fs/nfsd<br />
</code></p>
<p>After that I was able to mount the nfs share. It took me some time to figure it out and I think that there should be more specific error messages, because the one with <i>permission denied</i> is quite confusing.</p>
]]></content:encoded>
			<wfw:commentRss>http://slashroot.eu/2010/06/10/permission-denied-when-mounting-nfs-share/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Loading mysql database from compressed dump</title>
		<link>http://slashroot.eu/2010/04/09/loading-mysql-database-from-compressed-dump/</link>
		<comments>http://slashroot.eu/2010/04/09/loading-mysql-database-from-compressed-dump/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 09:25:08 +0000</pubDate>
		<dc:creator>root</dc:creator>
				<category><![CDATA[backup]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[oneliners]]></category>

		<guid isPermaLink="false">http://slashroot.eu/?p=193</guid>
		<description><![CDATA[Today I had to load database on mysql. There`s nothing new or exciting about it, but I encountered few problems. First one is that dump was quite big (few gigabytes) and it was compressed with gzip. (G)Unzipping it simply to a file would take some time, waste space on disk and it wasn`t the right [...]]]></description>
			<content:encoded><![CDATA[<p>Today I had to load database on mysql. There`s nothing new or exciting about it, but I encountered few problems. First one is that dump was quite big (few gigabytes) and it was compressed with gzip. (G)Unzipping it simply to a file would take some time, waste space on disk and it wasn`t the right way <img src='http://slashroot.eu/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  So here how I managed to decompress it and load it at the same time:</p>
<pre>gunzip -c mydbdump.sql.gz|mysql -umyuser -pmypass mydb
</pre>
<p>But then I found another problem &#8211; in my dump there was hardcoded database name. I wasn`t recovering that database, but just wanted to load it to a diffrent one. Names weren`t the same so it failed to load. I looked at the begining of that file using <strong>head </strong>command, as opening so huge file in vi(m) would probably kill the server. I found that there was two sql commands that creates database itself and use it (sql <em>use</em> command). So with a little help of <strong>sed</strong> I managed to modify my command so it looked like this:</p>
<pre>
gunzip -c mydbdump.sql.gz| sed -e '1,30s/old_dbname/mydb/'| mysql -umyuser -pmypass mydb
</pre>
<p>I limited sed`s search&amp;replace to first 30 lines, because database name was at the start of the dump file and I didn`t want to mess with the rest of the file <img src='http://slashroot.eu/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://slashroot.eu/2010/04/09/loading-mysql-database-from-compressed-dump/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Advantages of software raid</title>
		<link>http://slashroot.eu/2010/04/02/advantages-of-software-raid/</link>
		<comments>http://slashroot.eu/2010/04/02/advantages-of-software-raid/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 08:07:55 +0000</pubDate>
		<dc:creator>root</dc:creator>
				<category><![CDATA[backup]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[raid]]></category>
		<category><![CDATA[linux raid backup]]></category>

		<guid isPermaLink="false">http://slashroot.eu/?p=184</guid>
		<description><![CDATA[Why using software raid when there are plenty hardware raid controllers with dedicated processors for checksum calculations, dedicated memory, cache and bbu? Well there is one major advantage of software raid solutions &#8211; hardware independence. Recently we had a simultaneously crash of two disks in raid5 on 3ware 9550-sxu controller. That`s a real bad luck [...]]]></description>
			<content:encoded><![CDATA[<p>Why using software raid when there are plenty hardware raid controllers with dedicated processors for checksum calculations, dedicated memory, cache and bbu? Well there is one major advantage of software raid solutions &#8211; hardware independence.<br />
Recently we had a simultaneously crash of two disks in <strong>raid5</strong> on <strong>3ware 9550-sxu</strong> controller. That`s a real bad luck :-&gt; Of course we recovered data from backups, but before that we tried to rebuild array. We discovered that one dik had crashed, but the other had just few bad sectors. As an experiment we cloned that disk without these few sectors and tried to rebuild the array. Unfortunatelly controller didn`t recognize that disk as a member of the array. It turned out that <strong>3ware</strong> controller appends serial numbers of all members of array at the end of disks with a checksum (we tried to replace serial number of cloned disk with no luck).<br />
So how would it look on software raid? Much easier. Linux for example writes only array identificator (UUID) so disk cloning is possible. Furthermore disks can be transfered to another hardware. With 3ware controller in case of its failure we would have to find another 3ware controller (probably the same model).<br />
So a lesson has been taught &#8211; don`t rely on hardware raid, use <strong>raid6</strong> when possible and keep your backups safe because they may save your ass someday <img src='http://slashroot.eu/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://slashroot.eu/2010/04/02/advantages-of-software-raid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HOWTO Massive virtual hosting on tomcat</title>
		<link>http://slashroot.eu/2010/01/07/howto-massive-virtual-hosting-on-tomcat/</link>
		<comments>http://slashroot.eu/2010/01/07/howto-massive-virtual-hosting-on-tomcat/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 07:33:54 +0000</pubDate>
		<dc:creator>root</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://slashroot.eu/?p=148</guid>
		<description><![CDATA[I found out today that tomcat virtual hosts are pretty lame. I thought that these all java based tomcat`s fancy plugins are much more powerful than old, simpleapache httpd. Well they aren`t. I wasn`t able to configure massive virtual hosting for servlets. I wanted to run diffrent web application based on domain name that comes [...]]]></description>
			<content:encoded><![CDATA[<p>I found out today that tomcat virtual hosts are pretty lame. I thought that these all java based tomcat`s fancy plugins are much more powerful than old, <em>simple</em>apache httpd. Well they aren`t. I wasn`t able to configure massive virtual hosting for servlets. I wanted to run diffrent web application based on domain name that comes in URL. For example <code>myapp1.example.com</code> would run application <code>myapp1</code>, <code>myapp2.example.com</code> would run <code>myapp2</code>, etc. And there could be hundreds of them so I didn`t want to add hundreds of entries in <code>server.xml</code> config file. I`m a lazy person <img src='http://slashroot.eu/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>In order to configure virtual hosting based on above assumptions I used apache http server as a proxy to tomcat.<br />
First you need to add wildcard records to your domain (<code>example.com</code>) so that records of all its subdomains can be resolved to IP address of your server. Following record should be added to your bind server zone config:</p>
<pre>
*   IN   A   1.2.3.4
</pre>
<p>where <code>1.2.3.4</code> is IP address of your server.</p>
<p>Next you need to configure httpd server. Please make sure that you have ajp proxy module installed on your server, as connections to tomcat are based on AJP protocol. On CentOS/RHEL 5 this module is included in standard httpd package (see <code>/etc/httpd/conf.d/proxy_ajp.conf</code>).<br />
Now you need to create configuration for your virual hosts. I created a new file <code>/etc/httpd/conf.d/tomcat-vhosting.conf</code>:</p>
<pre>
UseCanonicalName Off
RewriteEngine On

# vhost map using perl script
RewriteMap vhost prg:/usr/local/bin/apache-getvhost.pl

# do no rewrite restricted names
RewriteCond %{SERVER_NAME} !^docs\.
RewriteCond %{SERVER_NAME} !^examples\.
RewriteCond %{SERVER_NAME} !^host-manager\.
RewriteCond %{SERVER_NAME} !^ROOT\.

# rewrite it
RewriteRule ^/(.*)$ ajp://localhost:8009/${vhost:%{SERVER_NAME}}/$1 [P]
</pre>
<p>Quite simple and cool, isn`t it? <img src='http://slashroot.eu/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  I`m sure that you probably expected <code>VirtualHost</code> directives, but all you need is a powerfull rewriting feature of apache. This configuration allows to access myapp application located in tomcat`s webapps directory via <code>http://myapp.example.com</code>.<br />
I used custom rewrite map which is a simple perl script. All it does is extract subdomain from server name based on URL.</p>
<p>Put the following in <code>/usr/local/bin/apache-getvhost.pl</code></p>
<pre>
#!/usr/bin/perl

$| = 1;

while (&lt;STDIN&gt;) {
  if (/(.*?)\.example\.com/)      {
      print $1."\n";
  } else {
      print $_."\n";
  }
}
</pre>
<p>and make it executable</p>
<pre>
chmod +x /usr/local/bin/apache-getvhost.pl
</pre>
<p>Now all you need to do is provide some applications to tomcat.</p>
]]></content:encoded>
			<wfw:commentRss>http://slashroot.eu/2010/01/07/howto-massive-virtual-hosting-on-tomcat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Booting Xen paravirtualized vm in rescue mode</title>
		<link>http://slashroot.eu/2009/12/22/booting-xen-paravirtualized-vm-in-rescue-mode/</link>
		<comments>http://slashroot.eu/2009/12/22/booting-xen-paravirtualized-vm-in-rescue-mode/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 13:33:45 +0000</pubDate>
		<dc:creator>root</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[virtualization]]></category>
		<category><![CDATA[lvm]]></category>
		<category><![CDATA[xen]]></category>

		<guid isPermaLink="false">http://slashroot.eu/?p=136</guid>
		<description><![CDATA[This is my first post in english. I am sorry if there are some mistakes &#8211; it is not my native language Recently I had to rename volume group in one of my virtual machines. It is based on CentOS (both dom0 and domU) and it was paravirtualized. I couldn`t do it on running system [...]]]></description>
			<content:encoded><![CDATA[<p>This is my first post in english. I am sorry if there are some mistakes &#8211; it is not my native language <img src='http://slashroot.eu/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Recently I had to rename volume group in one of my virtual machines. It is based on CentOS (both dom0 and domU) and it was paravirtualized. I couldn`t do it on running system because root partition was on logical volume. I had to boot the machine in rescue mode. I had no idea how to boot from CD/DVD iso image &#8211; AFAIK it is impossible on pv guests. I had to boot vm directly from kernel and initrd used in installation (both are xen aware). So I copied  them to ﻿<strong>/tmp/xen</strong> from <strong>/images/xen/</strong> on CD/DVD installation disc.</p>
<p>Then I had to comment out the following line from vm`s config file to bypass pygrub bootloader:<br />
<code><br />
#bootloader = "/usr/bin/pygrub"<br />
</code></p>
<p>Now I needed to tell my vm to use kernel and initrd I had previously copied so I added the following lines:<br />
<code><br />
kernel = "/tmp/xen/vmlinuz"<br />
ramdisk = "/tmp/xen/initrd.img"<br />
extra = "rescue method=http://192.168.0.2/install/centos/"<br />
</code></p>
<p>The last line passes extra arguments to kernel. There is a rescue keyword and a method which tells anaconda installer to get install files from my http server.</p>
<p>After that I was able to boot vm in rescue and rename my LVM virtual group.</p>
]]></content:encoded>
			<wfw:commentRss>http://slashroot.eu/2009/12/22/booting-xen-paravirtualized-vm-in-rescue-mode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Klastrowy LVM i Xen</title>
		<link>http://slashroot.eu/2009/11/23/klastrowy-lvm-i-xen/</link>
		<comments>http://slashroot.eu/2009/11/23/klastrowy-lvm-i-xen/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 19:19:45 +0000</pubDate>
		<dc:creator>root</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[virtualization]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[clvm]]></category>
		<category><![CDATA[lvm]]></category>
		<category><![CDATA[xen]]></category>

		<guid isPermaLink="false">http://slashroot.eu/?p=121</guid>
		<description><![CDATA[Bardzo intensywnie wykorzystuję wirtualizację jaką oferuje CentOS, czyli opensource`ową wersję Xena. W połączeniu z LVM można bardzo efektywnie zarządzać maszynami m.in. poprzez snapshoty. Dodatkowo zastosowanie LVM jako backendu storage`owego owocuje wysoką wydajnością. Xen posiada również możliwość migracji maszyn. Funkcja ta znana jako live migration jest odpowiednikiem vmotion dla produktów VMware. Można ją wykorzystać jedynie w [...]]]></description>
			<content:encoded><![CDATA[<p>Bardzo intensywnie wykorzystuję wirtualizację jaką oferuje CentOS, czyli opensource`ową wersję Xena. W połączeniu z LVM można bardzo efektywnie zarządzać maszynami m.in. poprzez snapshoty. Dodatkowo zastosowanie LVM jako backendu storage`owego owocuje wysoką wydajnością.</p>
<p>Xen posiada również możliwość migracji maszyn. Funkcja ta znana jako <em>live migration</em> jest odpowiednikiem <em>vmotion</em> dla produktów VMware. Można ją wykorzystać jedynie w przypadku, gdy wszystkie serwery <em>dom0</em> mają dostęp do współdzielonego storage`u. Najłatwiej jest wykorzystać zasób NFS podmontowany na wszystkich serwerach, a maszyny wirtualne instalować na plikach (obrazy dysków) tam umieszczonych. Oczywiście tracimy na wydajności, a poza tym NFS nie wydaje się dobrym pomysłem dla większych instalacji.<br />
I tu z pomocą przychodzi klastrowa odmiana LVM (<strong>CLVM</strong>). W RHEL/CentOS demon zarządzający klastrową częścią LVM (clvmd) komunikuje się z menadżerem klastra <strong>RHCS</strong> (<em>Red Hat Cluster Suite</em>). Mi osobiście to niezbyt pasuje. Nie tylko chyba ja uważam, że twór RHCS nie jest jeszcze stabilny ani też łatwy w konfiguracji i zarządzaniu/utrzymaniu. Ale to już chyba temat na odrębny wpis. Ku czemu innemu zmierzam. Mianowicie bardzo zainteresował mnie <a href="http://www.pixelchaos.net/2009/04/23/openais-an-alternative-to-clvm-with-cman/">ten</a> wpis. Okazuje się, że jest możliwe zmuszenie CLVM do działania bez skonfigurowanego RHCS! Należy zamiast tego użyć openais, który i tak wchodzi w skład RHCS. Jako odrębna część jest jednak o wiele przyjemniejsza w zarządzaniu i konfiguracji. Zachęcony wspomnianym wpisem przystąpiłem do pracy. Udało mi się przerobić paczkę <strong>lvm2-cluster</strong>, tak aby linkowała się z openais. Wpis ten byłby chyba pierwszym howto w sieci opisującym ten proces dla systemów RHEL/CentOS. Niestety w trakcie działania pojawiają się wycieki w pamięci w demonie <strong>aisexec</strong>. Przy każdorazowym wysłaniu wiadomości do aisexec przez demon clvmd ten pierwszy rezerwuje około <strong>6MB</strong> pamięci i nie zwalnia jej poprawnie. Kilkunastogodzinne próby nie przyniosły rozwiązania. Wielka szkoda. Byłaby to świetna wiadomość i dalsze pole do eksperymentowania. Liczę, że uda mi się jeszcze powrócić do tematu, a o rezultatach postaram się niezwłocznie poinformować.</p>
]]></content:encoded>
			<wfw:commentRss>http://slashroot.eu/2009/11/23/klastrowy-lvm-i-xen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Softraid i autodetekcja</title>
		<link>http://slashroot.eu/2009/10/06/softraid-i-autodetekcja/</link>
		<comments>http://slashroot.eu/2009/10/06/softraid-i-autodetekcja/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 07:30:35 +0000</pubDate>
		<dc:creator>root</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[softraid]]></category>

		<guid isPermaLink="false">http://slashroot.eu/?p=113</guid>
		<description><![CDATA[Zdarzyło mi się niedawno dołączyć dodatkowy dysk do działającego już systemu celem utworzenia redundancji na wszystkich partycjach (lub też na wolumenach LVM). Wszystko to działo się na Ubuntu 8.04 LTS, a więc prawie na debianie Całość procesu jest dość prosta i opisywana już w wielu artykułach w sieci ( m.in. tutaj ). Wszędzie niemalże wspomina [...]]]></description>
			<content:encoded><![CDATA[<p>Zdarzyło mi się niedawno dołączyć dodatkowy dysk do działającego już systemu celem utworzenia redundancji na wszystkich partycjach (lub też na wolumenach LVM). Wszystko to działo się na Ubuntu 8.04 LTS, a więc <em>prawie</em> na debianie <img src='http://slashroot.eu/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Całość procesu jest dość prosta i opisywana już w wielu artykułach w sieci ( m.in. <a href="http://www.howtoforge.com/how-to-set-up-software-raid1-on-a-running-lvm-system-incl-grub-configuration-debian-lenny">tutaj</a> ). Wszędzie niemalże wspomina się o ustawianiu typu partycji na <strong>fd</strong>, czyli <strong>Linux raid autodetect</strong>. Nazwa sugeruje, że ma to coś wspólnego z autowykrywaniem raidu. Otóż okazuje się, że miało w przeszłości. Parametry konfiguracyjny <strong>CONFIG_MD_AUTODETECT</strong> zniknął już jakiś czas temu z kernela i tym samym zniknęła też autodetekcja. Opisuje to <a href="http://linux-raid.osdl.org/index.php/RAID_Boot">ten</a> artykuł. Jest tam geneza usunięcia autodetekcji i rozwiązanie problemu bootowania z raidu 1. Wiąże się to z odpowiednio wygenerowanym plikiem initramfs. Ja się złapałem na tym, że system nie wstawał poprawnie, gdyż liczyłem że odpowiednio poustawiane typy partycji zrobią swoje i podczas startu wszystkie macierze samoczynnie wystartują. Krótka analiza struktury initramfs i kilka minut na googlach przyniosły rozwiązanie. Musiałem powiadomić mdadm o istnieniu macierzy, a zatem po ich utworzeniu wywołać polecenie</p>
<p><code>mdadm --examine --scan &gt;&gt; /etc/mdadm.conf</code></p>
<p>Następnie należy wygenerować plik initramfs uwzględniający te zmiany &#8211; załączy on ten plik do swojego drzewa i podczas startu odpowiednio wywołany mdadm z poziomu initramfs wystartuje podane tam macierze.<br />
W Ubuntu generujemy nowy initramfs dla obecnego kernela poleceniem</p>
<p><code>update-initramfs -u</code></p>
<p>Teraz już możemy cieszyć się mirrorowaną partycją /boot.</p>
]]></content:encoded>
			<wfw:commentRss>http://slashroot.eu/2009/10/06/softraid-i-autodetekcja/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Proste statystyki wydruków z bazą sqlite</title>
		<link>http://slashroot.eu/2009/08/21/proste-statystyki-wydrukow-z-baza-sqlite/</link>
		<comments>http://slashroot.eu/2009/08/21/proste-statystyki-wydrukow-z-baza-sqlite/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 11:04:45 +0000</pubDate>
		<dc:creator>root</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[logs]]></category>
		<category><![CDATA[oneliners]]></category>

		<guid isPermaLink="false">http://slashroot.eu/?p=90</guid>
		<description><![CDATA[Potrzebowałem na szybko statystyk wydruków. Do tego skonstruowałem taki oto twór: perl -ne 'print "$1 $2\n" if /(\d+\/[a-zA-z]+\/20\d{2}).*for job (\d+)\./' /var/log/cups/error_log&#124;sort &#124;uniq &#124; awk '{print "insert into printouts values(\""$1"\","$2");"}'&#124; sqlite3 printouts.db Ten z pozoru niezgrabny jednolinijkowiec parsuje plik logów cupsa wyciągając z niego numer zadania i datę, a następnie wkłada to do prostej bazy sqlite`a. [...]]]></description>
			<content:encoded><![CDATA[<p>Potrzebowałem na szybko statystyk wydruków. Do tego skonstruowałem taki oto twór:</p>
<pre class='brush:perl'>
perl -ne 'print "$1 $2\n" if /(\d+\/[a-zA-z]+\/20\d{2}).*for job (\d+)\./' /var/log/cups/error_log|sort |uniq | awk '{print "insert into printouts values(\""$1"\","$2");"}'| sqlite3 printouts.db
</pre>
<p>Ten z pozoru niezgrabny jednolinijkowiec parsuje plik logów cupsa wyciągając z niego numer zadania i datę, a następnie <i>wkłada</i> to do prostej bazy sqlite`a.</p>
<p>Dzięki temu mogłem szybko wydobyć ilość wydruków na dzień. Przy niewielkiej modyfikacji można dołączyć inne pola i już grupować sobie w sqlu co tylko dusza zapragnie. Nie jest to może wyszukany przypadek &#8211; raczej ciekawostka. To samo można uzyskać również za pomocą <b>uniq -c</b>, ale perspektywy tego rozwiązania są o wiele większe.</p>
<p>Na koniec tylko polecenie tworzące trywialną strukturę bazy <b>printouts.db</b>:<br />
<code><br />
sqlite3 printouts.db 'create table printouts(date text,job int)'<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://slashroot.eu/2009/08/21/proste-statystyki-wydrukow-z-baza-sqlite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ujarzmione logi apache</title>
		<link>http://slashroot.eu/2009/08/12/ujarzmione-logi-apache/</link>
		<comments>http://slashroot.eu/2009/08/12/ujarzmione-logi-apache/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 10:35:03 +0000</pubDate>
		<dc:creator>root</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[logs]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://slashroot.eu/?p=68</guid>
		<description><![CDATA[Na co dzień pracuję z aplikacją, która wyrzuca bardzo dużo &#8220;śmieci&#8221; do logów. Tym samym zapycha ona error log, który z nazwy powinien zawierać błędy, a nie informacje o niezainicjalizowanej zmiennej X. Postanowiłem ukrócić ten proceder i filtrować wychodzące z procesów apache`a komunikaty. Wykorzystałem do tego perla, gdyż dość sprawnie radzi on sobie z obróbką [...]]]></description>
			<content:encoded><![CDATA[<p>Na co dzień pracuję z aplikacją, która wyrzuca bardzo dużo &#8220;śmieci&#8221; do logów. Tym samym zapycha ona error log, który z nazwy powinien zawierać błędy, a nie informacje o niezainicjalizowanej zmiennej X. Postanowiłem ukrócić ten proceder i filtrować wychodzące z procesów apache`a komunikaty.</p>
<p>Wykorzystałem do tego perla, gdyż dość sprawnie radzi on sobie z obróbką tekstu i wyrażeniami regularnymi. Poniżej zawartość skryptu <strong>apache-logfilter.pl</strong></p>
<pre class="brush:perl">
#!/usr/bin/perl -w

use strict;

$|=1;   # use unbuffered output

my $logfile;

# check if logfile was passed as 1st argument
if ($ARGV[0])   {
$logfile=$ARGV[0];
}

# assign /dev/null as logfile unless it is already defined
$logfile="/dev/null" unless ($logfile);

# set umask
umask 0022;
my $loghandler=open(LOGFILE,'&gt;&gt;',$logfile);

# autoflush file handler
select((select(LOGFILE), $| = 1)[0]);

# inifinite loop over input from STDIN
while (&lt;STDIN&gt;) {

# omit unwanted lines matching the following patterns
next if (/^Use of uninitialized value/);
next if (/^"my" variable/);
next if (/^Subroutine \w+ redefined/);
next if (/^Variable ".*?" will not stay shared/);
next if (/^Odd number of elements in hash/);
next if (/^Argument ".*?" isn't numeric/);
next if (/^Useless use of .*? in void context/);
next if (/^substr outside of string at/);
next if (/^Unquoted string ".*?" may clash/);
next if (/^Scalar value @.*? better written as/);
next if (/^Parentheses missing around/);

# print to our logfile
print LOGFILE "$_";
}
</pre>
<p>Posiadając już taki skrypt należy przekazać w konfiguracji apache`a jego wywołanie. Odbywa się to za pomocą <em>pipe`a</em> przez który przekazywane są komunikaty do skrypty. W tym przypadku jako parametr podana jest ścieżka do właściwego pliku logu, do którego dopisywane są wiadomości (nie należy zapomnieć o właściwiej konfiguracji logrotate!).<br />
Przykładowa część konfiguracji:</p>
<p><code><br />
ErrorLog "|/usr/local/bin/apache-logfilter.pl /var/log/apache/error_log"<br />
</code></p>
<p>Ciekawą rzeczą jaką napotkałem tutaj był problem buforowanego wyjścia. Otóż do logu nie docierały żadne nowe wiadomości. Wielokrotnie sprawdzałem poprawność skryptu i za każdym razem działał on poprawnie zapuszczony z palca. Po krótkich poszukiwaniach znalazłem zmienną <strong>$|</strong>, której to niezerowe ustawienie powinno mój problem rozwiązać. A jednak nie rozwiązało. Dopiero wymuszenie tego na uchwycie otwartego pliku dało pożądane rezultaty. Odpowiada za to następujące wywołanie:</p>
<p><code><br />
select((select(LOGFILE), $| = 1)[0]);<br />
</code></p>
<p>Teraz wszystko śmiga jak należy &#8211;  czytelność logów zwiększyła się znacząco, a ich rozmiar zmniejszył się kilkukrotnie.</p>
]]></content:encoded>
			<wfw:commentRss>http://slashroot.eu/2009/08/12/ujarzmione-logi-apache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Na tropach procesu</title>
		<link>http://slashroot.eu/2009/08/04/na-tropach-procesu/</link>
		<comments>http://slashroot.eu/2009/08/04/na-tropach-procesu/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 15:55:54 +0000</pubDate>
		<dc:creator>root</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[debug]]></category>

		<guid isPermaLink="false">http://slashroot.eu/?p=61</guid>
		<description><![CDATA[Obecnie nie potrafię sobie wyobrazić porządnego debugowania/troubleshootingu bez strace`a. Dzięki niemu jestem w stanie śledzić wywołania systemowe i wychwytywać wszelkie błędy w oprogramowaniu w sytuacjach gdy logi już nie wystarczają. Dodatkowo zawsze jest to ciekawie obejrzeć działanie &#8220;od kuchni&#8221;. Jak używać strace`a? Najłatwiej poprzedzić wywołanie programu poleceniem strace. Częściej jednak będziemy chcieli sprawdzić co robi [...]]]></description>
			<content:encoded><![CDATA[<p>Obecnie nie potrafię sobie wyobrazić porządnego debugowania/troubleshootingu bez<strong> strace`a</strong>. Dzięki niemu jestem w stanie śledzić wywołania systemowe i wychwytywać wszelkie błędy w oprogramowaniu w sytuacjach gdy logi już nie wystarczają. Dodatkowo zawsze jest to ciekawie obejrzeć działanie &#8220;od kuchni&#8221;.</p>
<p>Jak używać strace`a? Najłatwiej poprzedzić wywołanie programu poleceniem <strong>strace</strong>. Częściej jednak będziemy chcieli sprawdzić co robi dany proces uruchomiony już w tle. Wówczas należy wywołać:</p>
<p><code>strace -p PID_PROCESU</code></p>
<p>Jeśli program tworzy forki to również warto dodać parametr <strong>-f</strong> śledzący jego procesy potomne.</p>
]]></content:encoded>
			<wfw:commentRss>http://slashroot.eu/2009/08/04/na-tropach-procesu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
