<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="http://feedproxy.google.com/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feedproxy.google.com/~d/styles/itemcontent.css"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Linux by Examples</title>
	
	<link>http://linux.byexamples.com</link>
	<description>We explain every GNU/Linux command by examples in this blog!</description>
	<pubDate>Wed, 03 Dec 2008 02:59:16 +0000</pubDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feedproxy.google.com/LinuxByExamples" type="application/rss+xml" /><feedburner:emailServiceId>LinuxByExamples</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Python: Manipulate string or binary bytes with StringIO</title>
		<link>http://feedproxy.google.com/~r/LinuxByExamples/~3/femVfNGdStg/</link>
		<comments>http://linux.byexamples.com/archives/483/python-manipulate-string-or-binary-bytes-with-stringio/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 00:55:50 +0000</pubDate>
		<dc:creator>mysurface</dc:creator>
		
		<category><![CDATA[Developer]]></category>

		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://linux.byexamples.com/?p=483</guid>
		<description><![CDATA[Sometimes it is not convenient to construct string using equal (=) like this:
str = "Hello, "
...
str = str + "my name is "
...
str = str + Name
print str
In python, we have string stream (StringIO) that will behave like file stream, you can construct your string like this:
str=StringIO()
...
str.write("Hello, ")
...
str.write("my name is ")
...
str.write(Name)
print str.getvalue()
The same way, you [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes it is not convenient to construct string using equal (=) like this:</p>
<pre><code>str = "Hello, "
...
str = str + "my name is "
...
str = str + Name
print str</code></pre>
<p>In python, we have string stream (StringIO) that will behave like file stream, you can construct your string like this:</p>
<pre><code>str=StringIO()
...
str.write("Hello, ")
...
str.write("my name is ")
...
str.write(Name)
print str.getvalue()</code></pre>
<p>The same way, you can construct your binary bytes with StringIO and write it into file once you are done.</p>
<pre><code>
bin=StringIO()
bin.write("/x5F/x5F%c" % 0xFF)
...
file = open ("my.bin","wb")
file.write(bin.getvalue())
file.close()</code></pre>
<div class="aizatto_related_posts"><span class="aizatto_related_posts_header" >Related Posts</span><br/><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/478/python-writing-binary-file/" rel="bookmark" title="Permanent Link: python: writing binary file" >python: writing binary file</a></span><div class="aizatto_related_posts_excerpt">Python is the best scripting language which I found it out perform Bash script as well as Lua. I like python's scripting...</div><p></p><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/97/reverse-a-string/" rel="bookmark" title="Permanent Link: Reverse a string" >Reverse a string</a></span><div class="aizatto_related_posts_excerpt">python provides a -c option to accept and run a script line.

To reverse a string like this one: "toydi deified idiot"...</div><p></p><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/364/python-manipulate-date-and-time-variables/" rel="bookmark" title="Permanent Link: Python: Manipulate Date and Time variables" >Python: Manipulate Date and Time variables</a></span><div class="aizatto_related_posts_excerpt">When comes to data time related calculations, we usually calculate for time difference, for example How long is the down...</div><p></p></div>
<p><a href="http://feedads.googleadservices.com/~a/_tA68qlEx7iCII-eDsamoC-KFGI/a"><img src="http://feedads.googleadservices.com/~a/_tA68qlEx7iCII-eDsamoC-KFGI/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/LinuxByExamples/~4/femVfNGdStg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://linux.byexamples.com/archives/483/python-manipulate-string-or-binary-bytes-with-stringio/feed/</wfw:commentRss>
		<feedburner:origLink>http://linux.byexamples.com/archives/483/python-manipulate-string-or-binary-bytes-with-stringio/</feedburner:origLink></item>
		<item>
		<title>python: writing binary file</title>
		<link>http://feedproxy.google.com/~r/LinuxByExamples/~3/Nw5Y6KSo6GY/</link>
		<comments>http://linux.byexamples.com/archives/478/python-writing-binary-file/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 06:06:34 +0000</pubDate>
		<dc:creator>mysurface</dc:creator>
		
		<category><![CDATA[python]]></category>

		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://linux.byexamples.com/?p=478</guid>
		<description><![CDATA[Python is the best scripting language which I found it out perform Bash script as well as Lua. I like python&#8217;s scripting syntax, which is make sense and very convenient in string manipulations. Its now come to binary format manipulation, how convenient is python?
I have carry out some research on python into writing binary files. [...]]]></description>
			<content:encoded><![CDATA[<p>Python is the best scripting language which I found it out perform Bash script as well as Lua. I like python&#8217;s scripting syntax, which is make sense and very convenient in string manipulations. Its now come to binary format manipulation, how convenient is python?</p>
<p>I have carry out some research on python into writing binary files. Either writing byte by byte manually, construct a binary stream then write it one short, or convert it from hex string, they are easy to write in python.</p>
<p>To open a file for binary writing is easy, it is the same way you do for reading, just change the mode into &#8220;wb&#8221;.</p>
<pre><code>file = open("test.bin","wb")</code></pre>
<p><strong>But, how to write the binary byte into the file? </strong><br />
You may write it straight away with hex code like this:</p>
<pre><code>file.write("\x5F\x9D\x3E")
file.close()
</code></pre>
<p>Now, check it out with hexedit, </p>
<pre><code>hexedit test.bin</code></pre>
<p>You will see this:</p>
<pre><code>00000000   5F 9D 3E                                                                                                _.>
00000020
00000040
</code></pre>
<p>Now, open the file to append more bytes:</p>
<pre><code>file = open("test.bin","ab")</code></pre>
<p><strong>What if I want to store by bin value into a stream and write it one short?</strong></p>
<pre><code>s ="\x45\xF3"
s = s + "%c%c" % (0x45,0xF3)
file.write(s)
file.close()
</code></pre>
<p><strong>Any convenient ways if I can obtained a hex string, and want to convert it back to binary format?</strong><br />
Yes, you just need to import binascii</p>
<pre><code>import binascii
hs="5B7F888489FEDA"
hb=binascii.a2b_hex(hs)
file.write(hb)
file.close()</code></pre>
<p>Isn&#8217;t it easy? I love python. You may want to discover more functions of binascii with <a href="http://linux.byexamples.com/archives/367/experiencing-with-ipython/">ipython</a>.</p>
<div class="aizatto_related_posts"><span class="aizatto_related_posts_header" >Related Posts</span><br/><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/483/python-manipulate-string-or-binary-bytes-with-stringio/" rel="bookmark" title="Permanent Link: Python: Manipulate string or binary bytes with StringIO" >Python: Manipulate string or binary bytes with StringIO</a></span><div class="aizatto_related_posts_excerpt">Sometimes it is not convenient to construct string using equal (=) like this:
str = "Hello, "
...
str = str + "my nam...</div><p></p><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/69/convert-perl-scripts-into-binaries/" rel="bookmark" title="Permanent Link: convert perl scripts into binaries" >convert perl scripts into binaries</a></span><div class="aizatto_related_posts_excerpt">You can covert perl script into ELF binary files, c source code, bytecode etc. You do this my using perlcc.

You can h...</div><p></p><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/365/python-convey-the-exception-traceback-into-log-file/" rel="bookmark" title="Permanent Link: python: convey the exception traceback into log file" >python: convey the exception traceback into log file</a></span><div class="aizatto_related_posts_excerpt">Python is the interpreter language, you do not need to compile your code, and also you have no ways to check for your sy...</div><p></p></div>
<p><a href="http://feedads.googleadservices.com/~a/MKp8hCEPhE9k2Jxx1k0euEKkwGY/a"><img src="http://feedads.googleadservices.com/~a/MKp8hCEPhE9k2Jxx1k0euEKkwGY/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/LinuxByExamples/~4/Nw5Y6KSo6GY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://linux.byexamples.com/archives/478/python-writing-binary-file/feed/</wfw:commentRss>
		<feedburner:origLink>http://linux.byexamples.com/archives/478/python-writing-binary-file/</feedburner:origLink></item>
		<item>
		<title>Bash script that process input from pipeline or file redirection</title>
		<link>http://feedproxy.google.com/~r/LinuxByExamples/~3/6ughQZW3qJs/</link>
		<comments>http://linux.byexamples.com/archives/474/bash-script-that-process-input-from-pipeline-or-file-redirection/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 02:20:09 +0000</pubDate>
		<dc:creator>mysurface</dc:creator>
		
		<category><![CDATA[Bash]]></category>

		<category><![CDATA[pipeline]]></category>

		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://linux.byexamples.com/?p=474</guid>
		<description><![CDATA[I remember I wrote a post regarding how to makes python processing string from the pipeline stream. This time, I find the needs to do it in bash script.
I created a hex string splitter script for my friend who needs to decode the raw data that will be written in hex string such as &#8220;5F443D95FEA3D4787AEDC4&#8243;. [...]]]></description>
			<content:encoded><![CDATA[<p>I remember I wrote a post regarding <a href="python: handle string from pipelines and list of param">how to makes python processing string from the pipeline stream</a>. This time, I find the needs to do it in bash script.</p>
<p>I created a hex string splitter script for my friend who needs to decode the raw data that will be written in hex string such as <strong>&#8220;5F443D95FEA3D4787AEDC4&#8243;</strong>. Every time, he split them byte by byte manually into this form (<strong>&#8220;5F 44 3D 95 FE A3 D4 78 7A ED C4&#8243;</strong>) for better reading. He was complain that the manual process was always bothering him. I told him that can be done by writting a simple bash script.</p>
<p>My hexsplit.sh will do this:</p>
<pre><code>./hexsplit.sh "5F443D95FEA3D4787AEDC4"</code></pre>
<p>But what if he grep this hex string from other file? Or what if the hex string are stored in a file? I want my bash script to be able to process hex string from pipeline stream as well as file redirection too, like this:</p>
<pre><code> grep "hex" dummy.log | cut -d"]" -f2 | ./hexsplit.sh</code></pre>
<p>or like this:</p>
<pre><code> ./hexsplit.sh &lt; dummy.log</code></pre>
<p>How to write this hexsplit.sh?</p>
<p>hexsplit.sh</p>
<pre><code>
#!/bin/bash

if [ -e $1 ] ;then read str; else str=$1;fi
len=`expr length $str`
for (( a=0; a<=$len; a=a+2 )); do echo -n ${str:a:2}" "; done
echo ""
</code></pre>
<p>The important line is the <strong>if statement</strong>. If there are no argument specified ( -e $1), I <strong>read</strong> from the stream, else i take it from $1 ( param 1). It is so simple isn&#8217;t it?</p>
<p>Have fun!</p>
<div class="aizatto_related_posts"><span class="aizatto_related_posts_header" >Related Posts</span><br/><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/343/python-handle-string-from-pipelines-and-list-of-param/" rel="bookmark" title="Permanent Link: python: handle string from pipelines and list of param" >python: handle string from pipelines and list of param</a></span><div class="aizatto_related_posts_excerpt">While I was searching ways to implement pipeline input for my python apps, I read an article from linuxjournal.com that ...</div><p></p><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/236/bash-timed-read-input/" rel="bookmark" title="Permanent Link: Bash: timed read input" >Bash: timed read input</a></span><div class="aizatto_related_posts_excerpt">For some critical task, you just can't wait for user response forever. If the user do not respond to input after certain...</div><p></p><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/165/set-the-default-xinput-to-scim-using-im-switch/" rel="bookmark" title="Permanent Link: Set the default xinput to scim using im-switch" >Set the default xinput to scim using im-switch</a></span><div class="aizatto_related_posts_excerpt">If you are a chinese writer, or you want to use chinese input under english locale ( default locale ). Usually people us...</div><p></p></div>
<p><a href="http://feedads.googleadservices.com/~a/-NuozocIOvvON4EOZPTPxGqoYnc/a"><img src="http://feedads.googleadservices.com/~a/-NuozocIOvvON4EOZPTPxGqoYnc/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/LinuxByExamples/~4/6ughQZW3qJs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://linux.byexamples.com/archives/474/bash-script-that-process-input-from-pipeline-or-file-redirection/feed/</wfw:commentRss>
		<feedburner:origLink>http://linux.byexamples.com/archives/474/bash-script-that-process-input-from-pipeline-or-file-redirection/</feedburner:origLink></item>
		<item>
		<title>List command line history with timestamp</title>
		<link>http://feedproxy.google.com/~r/LinuxByExamples/~3/5JqAAu8OjxI/</link>
		<comments>http://linux.byexamples.com/archives/467/list-command-line-history-with-timestamp/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 18:23:02 +0000</pubDate>
		<dc:creator>mysurface</dc:creator>
		
		<category><![CDATA[Common]]></category>

		<category><![CDATA[history]]></category>

		<category><![CDATA[last]]></category>

		<guid isPermaLink="false">http://linux.byexamples.com/?p=467</guid>
		<description><![CDATA[History is a common command for shell to list out all the executed commands. It is very useful when it comes to investigation on what commands was executed that tear down the server. With the help of last command, you be able to track the login time of particular user as well as the the [...]]]></description>
			<content:encoded><![CDATA[<p>History is a common command for shell to list out all the executed commands. It is very useful when it comes to investigation on what commands was executed that tear down the server. With the help of <strong>last</strong> command, you be able to track the login time of particular user as well as the the duration of the time he/she stays login.</p>
<pre><code>last
...
mysurface    tty7         :0               Mon Oct  6 20:07 - down   (00:00)
reboot   system boot  2.6.24.4-64.fc8  Mon Oct  6 20:06          (00:00)
mysurface    pts/8        10.168.28.44     Mon Oct  6 17:42 - down   (01:58)
mysurface    pts/7        :0.0             Mon Oct  6 17:41 - 19:40  (01:59)
mysurface    pts/6        :0.0             Mon Oct  6 17:27 - 19:40  (02:13)
mysurface    pts/5        :0.0             Mon Oct  6 17:27 - 19:40  (02:13)
mysurface    pts/5        :0.0             Mon Oct  6 15:52 - 15:59  (00:07)
...</code></pre>
<p>If the command line history could provides the date time of the commands being executed, that may really narrow down the scope of the user actions that cause the server malfunction. By default, history do not append with timestamp, but it is easy to configure it to display timestamp, you just need to set one environment variable <strong>HISTTIMEFORMAT</strong>.</p>
<p><strong>HISTTIMEFORMAT</strong> takes format string of <strong>strftime</strong>. Check out the strftime manual to choose and construct the timestamp that suit your taste. My favorite is &#8220;%F %T &#8220;.</p>
<pre><code>export HISTTIMEFORMAT="%F %T "</code></pre>
<p>Execute <strong>history</strong> again and you will see the effect on the spot, bare in mind that the timestamp for command lines that executed at previous sessions may not valid, as the time was not tracked.</p>
<pre><code>...
  994  2008-10-16 02:27:40 exit
  995  2008-10-16 01:12:20 iptables -nL
  996  2008-10-16 01:47:46 vi .bash_profile
  997  2008-10-16 01:47:55 history
  998  2008-10-16 01:48:03 . .bash_profile
  999  2008-10-16 01:48:04 history
 1000  2008-10-16 01:48:09 exit
 1001  2008-10-16 02:27:43 history
...</code></pre>
<p>I would suggest you to put the export into ~/.bash_profile as well as /root/.bash_profile. In case you do not have .bash_profile, you can choose to put into ~/.bashrc.</p>
<p>Don&#8217;t mess up my servers! Your actions will be track!</p>
<div class="aizatto_related_posts"><span class="aizatto_related_posts_header" >Related Posts</span><br/><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/38/retrieve-back-command-been-enter/" rel="bookmark" title="Permanent Link: Retrieve Back Command Been Enter" >Retrieve Back Command Been Enter</a></span><div class="aizatto_related_posts_excerpt">Everytime you enter a command in shell. It will be store it a file for later use, so  you can retrieve back the command ...</div><p></p><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/332/what-is-your-10-common-linux-commands/" rel="bookmark" title="Permanent Link: what is your 10 common linux commands?" >what is your 10 common linux commands?</a></span><div class="aizatto_related_posts_excerpt">Dear command line ninjas, Mr CLI and keyboard pianist:

What is your regular command you use? I am sure you must think...</div><p></p><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/34/secure-file-transfer-through-ssh/" rel="bookmark" title="Permanent Link: secure file transfer through ssh" >secure file transfer through ssh</a></span><div class="aizatto_related_posts_excerpt">If you want to transfer one or few files which you have know the location, scp would be enough. SCP example will be HERE...</div><p></p></div>
<p><a href="http://feedads.googleadservices.com/~a/Szyzoe8U-gsy_s_W2OZYz3CE6Xc/a"><img src="http://feedads.googleadservices.com/~a/Szyzoe8U-gsy_s_W2OZYz3CE6Xc/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/LinuxByExamples/~4/5JqAAu8OjxI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://linux.byexamples.com/archives/467/list-command-line-history-with-timestamp/feed/</wfw:commentRss>
		<feedburner:origLink>http://linux.byexamples.com/archives/467/list-command-line-history-with-timestamp/</feedburner:origLink></item>
		<item>
		<title>XSLT processor command line</title>
		<link>http://feedproxy.google.com/~r/LinuxByExamples/~3/8ubBto8e744/</link>
		<comments>http://linux.byexamples.com/archives/463/xslt-processor-command-line/#comments</comments>
		<pubDate>Sun, 07 Sep 2008 10:33:08 +0000</pubDate>
		<dc:creator>mysurface</dc:creator>
		
		<category><![CDATA[Misc]]></category>

		<guid isPermaLink="false">http://linux.byexamples.com/?p=463</guid>
		<description><![CDATA[XSLT stand for XSL transformation, and XSL is EXtensible Stylesheet Language, it is XML-based Stylesheet Language defined by W3C. XSLT is one of the famous XML technology, XML that uses XSL needs transformation before that make sense. Some application such as firefox browser do support XSLT, with xsl source specified, it will be transform automatically.
If [...]]]></description>
			<content:encoded><![CDATA[<p>XSLT stand for XSL transformation, and XSL is EXtensible Stylesheet Language, it is XML-based Stylesheet Language defined by W3C. XSLT is one of the famous XML technology, XML that uses XSL needs transformation before that make sense. Some application such as firefox browser do support XSLT, with xsl source specified, it will be transform automatically.</p>
<p>If you have XSL, and xml that uses XSL, you can also transform by using a command call xsltproc. xsltproc is a tool from libxslt. The usage is straight forward:</p>
<pre><code>xsltproc mytemp.xsl mytarget.xml</code></pre>
<p>The line above will dump the transformed xml to standard output, which you can redirect it to any files. </p>
<p>With -o, the transformed xml will be dumped into file.</p>
<pre><code>xsltproc mytemp.xsl mytarget.xml -o myresult.xml</code></pre>
<p>p.s. For xsltproc, the targeted xml do not need to specified the xsl inline such as:</p>
<pre><code>&lt;?xml-stylesheet href="mytemp.xsl" type="text/xsl" ?&gt;</code></pre>
<p>To know more about XSLT check out <a href="http://www.w3schools.com/xsl/xsl_languages.asp">W3C XSLT tutorial</a>, or check out ways of <a href="http://toolbox.byexamples.com/2008/09/3-ways-of-transform-xml-with-xslt/">transform XML with XSLT</a>. You can also get some samples from the W3C tutorial to try out xsltproc.</p>
<div class="aizatto_related_posts"><span class="aizatto_related_posts_header" >Related Posts</span><br/><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/185/get-to-know-your-hardware-information/" rel="bookmark" title="Permanent Link: get to know your hardware information" >get to know your hardware information</a></span><div class="aizatto_related_posts_excerpt">You can obtain cpu and memory info by doing this:

cat /proc/cpuinfo
cat /proc/meminfo

But what if you want to hav...</div><p></p><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/37/display-system-information/" rel="bookmark" title="Permanent Link: Display System Information" >Display System Information</a></span><div class="aizatto_related_posts_excerpt">When you log in to a machine, how you know about the machine information? May be have dozen of way to do so, but usually...</div><p></p><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/330/powertop-helps-to-save-40-of-power-consumption/" rel="bookmark" title="Permanent Link: powertop helps to save 40% of power consumption?" >powertop helps to save 40% of power consumption?</a></span><div class="aizatto_related_posts_excerpt">With PowerTOP, I managed to increase the battery life of my Panasonic R4 laptop from 4 to almost 7 hours
-- Keith Packa...</div><p></p></div>
<p><a href="http://feedads.googleadservices.com/~a/Z4xuPlbEJiWzU-KQNYVXuRjZMEU/a"><img src="http://feedads.googleadservices.com/~a/Z4xuPlbEJiWzU-KQNYVXuRjZMEU/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/LinuxByExamples/~4/8ubBto8e744" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://linux.byexamples.com/archives/463/xslt-processor-command-line/feed/</wfw:commentRss>
		<feedburner:origLink>http://linux.byexamples.com/archives/463/xslt-processor-command-line/</feedburner:origLink></item>
		<item>
		<title>KDE based Fluxbox open folder tips</title>
		<link>http://feedproxy.google.com/~r/LinuxByExamples/~3/1ny5v9_CRmk/</link>
		<comments>http://linux.byexamples.com/archives/459/kde-based-fluxbox-open-folder-tips/#comments</comments>
		<pubDate>Sat, 30 Aug 2008 07:29:43 +0000</pubDate>
		<dc:creator>mysurface</dc:creator>
		
		<category><![CDATA[fluxbox]]></category>

		<category><![CDATA[picasa]]></category>

		<category><![CDATA[gnome-do]]></category>

		<guid isPermaLink="false">http://linux.byexamples.com/?p=459</guid>
		<description><![CDATA[I am a KDE based Fluxbox user, I am face an issue that some of my gnome applications that have feature of allowing me to locate and open folder doesn&#8217;t really work as expected. Those gnome applications are gnome-do and picasa. When I open a folder from gnome-do or picasa, it will be open in [...]]]></description>
			<content:encoded><![CDATA[<p>I am a KDE based Fluxbox user, I am face an issue that some of my gnome applications that have feature of allowing me to locate and open folder doesn&#8217;t really work as expected. Those gnome applications are <strong>gnome-do</strong> and <strong>picasa</strong>. When I open a folder from gnome-do or picasa, it will be open in firefox. Instead, I want it to open at konqueror.</p>
<p>I didn&#8217;t find any solution for that, due to the fact there are not much KDE based Fluxbox users around. But, at last I figure out a work around.</p>
<p>I realized that those gnome applications will call xdg-open when it is asked to open the folders. xdg-open is a bash script that will checks for global environment variable $DE and decide what file browser to execute. I have extracted the important part for reference:</p>
<pre><code>
if [ x"$DE" = x"" ]; then
    # if BROWSER variable is not set, check some well known browsers instead
    if [ x"$BROWSER" = x"" ]; then
        BROWSER=htmlview:firefox:mozilla:netscape:links:lynx
    fi
    DE=generic
fi

case "$DE" in
    kde)
    open_kde "$url"
    ;;

    gnome)
    open_gnome "$url"
    ;;

    xfce)
    open_xfce "$url"
    ;;

    generic)
    open_generic "$url"
    ;;

    *)
    exit_failure_operation_impossible "no method available for opening '$url'"
    ;;
esac
</code></pre>
<p>The workaround is assign $DE with value &#8220;kde&#8221;, edit your ~/.bash_profile or ~/.bashrc with:</p>
<pre><code>export DE=kde</code></pre>
<p>Relogin again and it is done.</p>
<div class="aizatto_related_posts"><span class="aizatto_related_posts_header" >Related Posts</span><br/><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/328/compile-fluxbox-under-ubuntu/" rel="bookmark" title="Permanent Link: Compile Fluxbox under Ubuntu" >Compile Fluxbox under Ubuntu</a></span><div class="aizatto_related_posts_excerpt">I make a fresh install of kubuntu and apt-get Fluxbox from Ubuntu repository yesterday and tried to login to Fluxbox. Fi...</div><p></p><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/309/tabbed-browsing-file-manager/" rel="bookmark" title="Permanent Link: tabbed-browsing file manager" >tabbed-browsing file manager</a></span><div class="aizatto_related_posts_excerpt">I like nautilus file manager as it allows me to access samba drive, ftp site etc, but when it comes to file manipulation...</div><p></p><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/179/wmctrl-a-handy-tool-for-you-to-manipulate-windows/" rel="bookmark" title="Permanent Link: wmctrl, a handy tool for you to manipulate windows" >wmctrl, a handy tool for you to manipulate windows</a></span><div class="aizatto_related_posts_excerpt">Every piece of GUI programs is frame in a windows, windows have various behavior, either shading, sticky, minimized, max...</div><p></p></div>
<p><a href="http://feedads.googleadservices.com/~a/nAkf94ra35NcNsRGUnfWv1qE0-I/a"><img src="http://feedads.googleadservices.com/~a/nAkf94ra35NcNsRGUnfWv1qE0-I/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/LinuxByExamples/~4/1ny5v9_CRmk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://linux.byexamples.com/archives/459/kde-based-fluxbox-open-folder-tips/feed/</wfw:commentRss>
		<feedburner:origLink>http://linux.byexamples.com/archives/459/kde-based-fluxbox-open-folder-tips/</feedburner:origLink></item>
		<item>
		<title>Experiencing with vmware server and Sun xVM VirtualBox</title>
		<link>http://feedproxy.google.com/~r/LinuxByExamples/~3/Q4sUiWAnocI/</link>
		<comments>http://linux.byexamples.com/archives/438/experiencing-with-vmware-server-and-sun-xvm-virtualbox/#comments</comments>
		<pubDate>Sat, 16 Aug 2008 17:40:59 +0000</pubDate>
		<dc:creator>mysurface</dc:creator>
		
		<category><![CDATA[Misc]]></category>

		<category><![CDATA[VirtualBox]]></category>

		<category><![CDATA[vmware]]></category>

		<guid isPermaLink="false">http://linux.byexamples.com/?p=438</guid>
		<description><![CDATA[Recently I have tried Sun xVM VirtualBox 1.6.4 , I have compare vbox with Vmware server 1.0.4. After couple days of testing, its time for me to share some personal findings towards them. I may not able to provide graphs, and accurate figures to shows their performance and specification, but what I do is to [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I have tried Sun xVM VirtualBox 1.6.4 , I have compare vbox with Vmware server 1.0.4. After couple days of testing, its time for me to share some personal findings towards them. I may not able to provide graphs, and accurate figures to shows their performance and specification, but what I do is to only share my point of view as a layman, and how I like or dislike them based on the user experience.</p>
<p>First of all, let me list down my host machine specs:<br />
<strong>Dell Vostro 1400 with Intel Core 2 Duo CPU T5270  @ 1.40GHz, 2G Ram.</strong><br />
I use <strong>512 Mb</strong> Ram to load my guest os, I tried loading up <strong>myrinix live CD</strong>, as well as installed <strong>Windows XP.</strong><br />
Uses <strong>Fedora 8</strong>, my WM uses <strong>Fluxbox 1.0.0</strong>.</p>
<p>Before looking into performance and features, let us first look at the screenshot! I am loading up <a href="http://myrinix.com/">myrinix</a> live cd at both virtual tool. The reason I choose myrinix because this great Live CD pre install with vbox guest additions as well as vmware tools, so that I can enjoy the mouse integration to move my mouse IN and OUT the guest os.</p>
<p><strong>Virtual Box have separate window for virtual os settings and guest OS itself.</strong><br />
<a href="http://linux.byexamples.com/wp-content/uploads/2008/08/vbox1.png"><img src="http://linux.byexamples.com/wp-content/uploads/2008/08/vbox1-300x192.png" alt="" title="vbox1" width="300" height="192" class="alignnone size-medium wp-image-440" /></a></p>
<p><strong>Vmware Server makes every Guest OSes in MDI, separate each guest oses into tabs, and the guest os settings in sidebar, NEAT!</strong><br />
<a href="http://linux.byexamples.com/wp-content/uploads/2008/08/vmware1.png"><img src="http://linux.byexamples.com/wp-content/uploads/2008/08/vmware1-300x232.png" alt="" title="vmware1" width="300" height="232" class="alignnone size-medium wp-image-441" /></a></p>
<p><span id="more-438"></span></p>
<p><strong>Performance and Resources Usage</strong><br />
Seems both Vmware Server and Virtual Box loading speed are equally fast, and it speed close to native while I rambling in guest OS. I have such feeling of Vbox start up is a little bit faster than vmware, but uses more CPU resources than vmware. For saving and resuming guest os machine state, vbox really out performs vmware server, vbox takes less than 10 seconds to save a machines state and around 5 seconds to resume them, but vmware takes ages, even greater than shutdown and startup time, CRAZY!</p>
<p><strong>Networking</strong><br />
Vmware support various of networking, and it allows us to switch between them in real time. I can switch NAT and Bridge anytime with loaded guest os. If I want to share internet with my host, I choose NAT. I do this when my host accessing internet through wireless LAN. I choose bridge when I want my guest OS to obtain a different IP from DHCP server. Meaning my host and guest os have separate IP address. With that, my guest OS now can be accessed from the real LAN!</p>
<p><a href="http://linux.byexamples.com/wp-content/uploads/2008/08/vmware2.png"><img src="http://linux.byexamples.com/wp-content/uploads/2008/08/vmware2-300x139.png" alt="" title="vmware2" width="300" height="139" class="alignnone size-medium wp-image-442" /></a></p>
<p>Vbox also support various types of network mode too. By default, vbox uses NAT. Host Interface is equivalent to vmware Bridge mode. In order to allow Host Interface to be working, you need to setup manually, vbox does provides the guidelines for different host such as windows, solaris and Linux. But the steps is quite tedious and don&#8217;t bother trying out right now. Not to say you can&#8217;t switch network modes in real time, while your guest OS is running, the guest OS settings automatically disabled from configure. You can&#8217;t modify the settings even you save the guest os machine state, that is so ANNOYING!</p>
<p><a href="http://linux.byexamples.com/wp-content/uploads/2008/08/vbox2.png"><img src="http://linux.byexamples.com/wp-content/uploads/2008/08/vbox2-300x277.png" alt="" title="vbox2" width="300" height="277" class="alignnone size-medium wp-image-443" /></a></p>
<p>But vbox support four virtual network adapter, if you have properly setup the Host Interface, you can manipulate those virtual Ethernets to bind to different network interface provided that your host machine have multiple network interface too. Vbox also provides different Network Adapter Hardware(Adapter Type) for you to choose. With some specific guest OS, you need to choose the correct Adapter Type, else it won&#8217;t works. For example freebsd guest os needs PCnet-PCI II instead of PCnet-PC III. Well, I don&#8217;t know what is the different between those options and the purpose of providing those options.</p>
<p><strong>Disk Image format</strong><br />
Vmware supports only vmdk format, and that is its own disk image format. Vbox default disk image format is vdi, but vbox supports vmdk too!</p>
<p><strong>cd-rom support</strong><br />
Both vmware and vbox support mounting and unmounting cd-rom from iso as well as host cd-rom devices. In vbox always remember to unmount first before mounting a new one.</p>
<p><strong>Installing Windows XP</strong><br />
Both vmware and vbox gives a very good support for windows xp as guest os, such as Auto resize guest display ( Auto-fit Guest in vmware). Mouse integration allows moving mouse in and out the guest os. Those features will be activated after installing guest additions into windows xp guest os ( vmware tools for vmware).</p>
<p>Vbox provides Seamless Mode feature, which it blends the host and guest os together. Check out the screenshot!</p>
<p><strong>I am running Firefox 3 from both Linux and Windows XP side by side</strong><br />
<a href="http://linux.byexamples.com/wp-content/uploads/2008/08/vbox3.png"><img src="http://linux.byexamples.com/wp-content/uploads/2008/08/vbox3-300x187.png" alt="" title="vbox3" width="300" height="187" class="alignnone size-medium wp-image-449" /></a></p>
<p>While moving my guest os&#8217;s apps around my Linux desktop, I experience flickery in display, probably because I run this in Fluxbox, I should try to run this in KDE or gnome. </p>
<p>Vbox support folder sharing between guest os and host os, this is a demanding feature that vmware server doesn&#8217;t provide, but I heard this feature is available in vmware workstation.</p>
<p><strong>Some trivial Facts!</strong><br />
I am having dual boot for my laptop, meaning I have limited hardisk space for my ext3 partition, therefore I created vmdk format using <strong><a href="http://linux.byexamples.com/archives/category/misc/qemu/qemu-img/">qemu-img</a></strong> in my NTFS partition. After that, I load up my vbox and install Windows XP into the vmdk disk image. Next, I create a vmx file and try to load this vmdk at vmware server.<br />
( For more information regarding qemu and vmx, check out <a href="http://linux.byexamples.com/archives/424/virtualize-your-operating-system-with-qemu/">this post</a>.)</p>
<p>Ouch! vmware do not able to recognize this vmdk? I copy over the vmdk to ext3 and try again, it works! Meaning vmware for linux do not able to read the image in other filesystem except linux native filesystem? FUNNY! </p>
<p>Vmware virtualize different hardwares compare to vbox as well as qemu. There are risk of crashing windows if changes of hardwares, you will be throw into blue screen of death. But vmware handle it well, although I am installing windows in vbox, the windows is booting up nicely and detects the change of hardwares and depend me to just reactive windows. At this point, I shutdown my windows from vmware and try to boot it up from vbox, it crashed! I am in blue screen of death!</p>
<p><strong>Summary</strong><br />
Both vmware and vbox have its pros and cons, I enjoy both of them.</p>
<p>Vmware Server:<br />
1. Able to switch networks from NAT to Bridge mode in real time.<br />
2. Organize guest oses in tabs and have their settings in sidebar.<br />
3. Do not support File sharing. ( vmware workstation does but not vmware server)<br />
4. Saving and resuming guest os machine state takes longer time than startup and shutdown.<br />
5. Do not able to read disk image from NTFS and NAT filesystem.<br />
6. Able to handle windows without crashing where windows installed using different virtual tool.</p>
<p>Virtual Box:<br />
1. Provide 4 virtual network Adapter, but need manual setup Host Interface.<br />
2. Support both vdi and vmdk format.<br />
3. Seamless Mode for Windows XP guest OS is cool.<br />
4. Support File sharing within guest os and host os.<br />
5. Saving and resuming guest OS very fast.<br />
6. Setting disabled while guest OS is running or saved.</p>
<div class="aizatto_related_posts"><span class="aizatto_related_posts_header" >Related Posts</span><br/><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/120/get-to-know-what-web-server-a-site-used/" rel="bookmark" title="Permanent Link: get to know what web server a site used" >get to know what web server a site used</a></span><div class="aizatto_related_posts_excerpt">You can get the information of what web server a site used by refers to HTTP Header of a site, usually it is invisible f...</div><p></p><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/424/virtualize-your-operating-system-with-qemu/" rel="bookmark" title="Permanent Link: Virtualize your operating system with qemu" >Virtualize your operating system with qemu</a></span><div class="aizatto_related_posts_excerpt">

QEMU is a processor emulator, it allows you to run variety of unmodified guest operating systems such as Linux, Wind...</div><p></p><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/178/ssh-server-security-warning/" rel="bookmark" title="Permanent Link: ssh server security warning" >ssh server security warning</a></span><div class="aizatto_related_posts_excerpt">If you are hosting your ssh server to public, please remember to disable the root access. This is important! A lots of "...</div><p></p></div>
<p><a href="http://feedads.googleadservices.com/~a/ro_NeyjMn_Ak4iVS43AtKuDbmt0/a"><img src="http://feedads.googleadservices.com/~a/ro_NeyjMn_Ak4iVS43AtKuDbmt0/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/LinuxByExamples/~4/Q4sUiWAnocI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://linux.byexamples.com/archives/438/experiencing-with-vmware-server-and-sun-xvm-virtualbox/feed/</wfw:commentRss>
		<feedburner:origLink>http://linux.byexamples.com/archives/438/experiencing-with-vmware-server-and-sun-xvm-virtualbox/</feedburner:origLink></item>
		<item>
		<title>Virtualize your operating system with qemu</title>
		<link>http://feedproxy.google.com/~r/LinuxByExamples/~3/YtQ3WKwe9Oo/</link>
		<comments>http://linux.byexamples.com/archives/424/virtualize-your-operating-system-with-qemu/#comments</comments>
		<pubDate>Sat, 02 Aug 2008 03:57:53 +0000</pubDate>
		<dc:creator>mysurface</dc:creator>
		
		<category><![CDATA[qemu]]></category>

		<category><![CDATA[qemu-img]]></category>

		<category><![CDATA[vmware]]></category>

		<category><![CDATA[qemulator]]></category>

		<category><![CDATA[virtualization]]></category>

		<guid isPermaLink="false">http://linux.byexamples.com/?p=424</guid>
		<description><![CDATA[
QEMU is a processor emulator, it allows you to run variety of unmodified guest operating systems such as Linux, Windows, Solaris, Dos etc just like Vmware and VirtualBox. In fact VirtualBox dynamic recompiler are based on QEMU. QEMU supports emulating several hardware platforms, including x86, AMD64, Alpha, MIPS, ARM, PPC, SPARC etc.
QEMU comes with command [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://linux.byexamples.com/wp-content/uploads/2008/08/qemu.png"><img src="http://linux.byexamples.com/wp-content/uploads/2008/08/qemu-300x187.png" alt="" title="qemu" width="300" height="187" class="aligncenter size-medium wp-image-429" /></a></p>
<p><a href="http://bellard.org/qemu/">QEMU</a> is a processor emulator, it allows you to run variety of unmodified guest operating systems such as Linux, Windows, Solaris, Dos etc just like Vmware and VirtualBox. In fact VirtualBox dynamic recompiler are based on QEMU. QEMU supports emulating several hardware platforms, including x86, AMD64, Alpha, MIPS, ARM, PPC, SPARC etc.</p>
<p>QEMU comes with command line interface, where you pass your configurations by parameters, but there are 3rd party GUI front end, such as <a href="http://qemulator.createweb.de/">Qemulator</a> and <a href="https://gna.org/projects/qemulaunch/">Qemu-Launcher</a>. To improves the performance of QEMU, we needs either KQEMU kernel module or KVM. Both of them are accelerator that to increase the execution speed of QEMU. </p>
<p>In this post, I covers installation of QEMU as well as KQEMU. As well as simple example of the use of QEMU command lines, how to create image files that allows to execute by both QEMU as well as Vmware.</p>
<p><span id="more-424"></span></p>
<p><strong>Installation</strong><br />
I believes that you may download QEMU from your repository, which it may already comes with kqemu. You may also manually compile both qemu and kqemu. My Linux distro repository contains older version of qemu, therefore I choose to compile qemu and kqemu myself.</p>
<p>You can download both qemu and kqemu from <a href="http://bellard.org/qemu/download.html">http://bellard.org/qemu/download.html</a>.</p>
<p>Compilation and Installation for qemu and kqemu are straight forward. You just need to do the steps below:<br />
1. untar the archive.</p>
<p>2. compile </p>
<pre><code>./configure
make</code></pre>
<p>3. install using root permission</p>
<pre><code>make install</code></pre>
<p>kqemu is a kernel object, it may not auto reboot every time you reboot your machines, check out the kqemu installation for Linux <a href="http://bellard.org/qemu/kqemu-doc.html">HERE</a>. </p>
<p>To manually load kqemu, do this in root:</p>
<pre><code>mknod /dev/kqemu c 250 0
chmod 666 /dev/kqemu
/sbin/modprobe kqemu</code></pre>
<p><strong>Boot up live cd using QEMU</strong><br />
To check out the Live CD iso without have to burn it to CD, i usually use qemu. For this I really appreciate the flexibility of command line interface, without much clicks here and there, I boot up my Live CD with a single line of command.</p>
<p>For this illustration, I choose <a href="http://myrinix.com/www/">Myrinix</a>.  Myrinix is a multi purpose Portable Linux based on Debian SID. it can be in Live CD format ,USB drive as well as install in windows xp ntfs partition without modify the Master Boot Record (MBR). Myrinix also supply a series of application module that can be easily added later. You may download the latest Myrinix Live CD iso from <a href="http://myrinix.com/www/">HERE</a>.</p>
<p>Lets boot up the Live CD ISO now!</p>
<pre><code>qemu -cdrom myrinix-kde-200808.iso -m 512 -boot d</code></pre>
<p>Short and simple! Specified your iso file path at -cdrom, in case you want to load up the Live CD from the physical CD, you may change to -cdrom /dev/cdrom ( depends on your cdrom dev). -m 512 is to force qemu to use 512Mb on RAM, by default qemu uses only 128Mb. At last -boot d option indicates that I want qemu to boot up from cdrom.</p>
<p><a href="http://linux.byexamples.com/wp-content/uploads/2008/08/qemu1.png"><img src="http://linux.byexamples.com/wp-content/uploads/2008/08/qemu1-300x224.png" alt="" title="qemu1" width="300" height="224" class="aligncenter size-medium wp-image-430" /></a></p>
<p><strong>Verify kqemu is loaded</strong><br />
During loading the Live CD, you can verify whether kqemu is it loaded and in use. Press Ctrl+Alt 2, and type:</p>
<pre><code>info kqemu
kqemu support: enabled for user mode</code></pre>
<p>As long as I see the positive message, kqemu is successfully loaded and in used. Press Ctrl+Alt 1 to goes back the emulator screen.</p>
<p><strong>Connects to the Internet in guest OS</strong><br />
By default, qemu will act as dhcp server and support internet sharing from your Host machine. Therefore as long as my host have internet access, my guest OS in qemu may have internet access too.</p>
<p>Myrinix does not acquire IP from DHCP by default, I think a lots of Linux Live CD doesn&#8217;t do that too. Therefore I have to do it manually. Login to root and run dhclient on eth0.</p>
<pre><code>su -
dhclient eth0</code></pre>
<p><strong>Connects to Host Machines</strong><br />
I can obtain virtual IP for internet sharing from 10.0.2.2 by default, the same way I may also connect to my host machine by this IP. </p>
<pre><code>ssh mysurface@10.0.2.2</code></pre>
<p>If my guest Linux have KDE installed, I may use fish in Konqueror for file transferring from my host machine to my current guest Linux. Check out how to do that at <a href="http://linux.byexamples.com/archives/390/how-to-transfer-files-and-folders-through-ssh-by-drag-and-drop/">HERE</a>.</p>
<p>Qemu provides more options, just type qemu, you will get a full list of options it support, check out the <a href="http://bellard.org/qemu/user-doc.html">user document</a> for more details information.</p>
<p><strong>Install a guest OS</strong><br />
To install a guest OS using qemu, first thing I need to do is to create an image file using qemu-img. qemu-img support various of file format including vmdk. qemu support loading vmdk image files. Vmware image file is in vmdk format. Bare in mind, load up vmdk files created by vmware at YOUR OWN RISK. (I have a bad experience on loading up Red Hat ES4 vmdk created by vmware server, which it fails to boot up X after booting it up by qemu. My guess is both qemu and vmware emulates different set of hardware drivers. Well, at last I manage to fix it by reinstall vmware tools in Red Hat ES4.)</p>
<p>To create a 10G disk image in vmdk format using qemu-img like this: (Don&#8217;t worry, 10G disk image do not actually eats 10G of your physical Hard disk space)</p>
<pre><code>qemu-img create -f vmdk myos.vmdk 10G</code></pre>
<p>Now I may load up your installer CD with disk image with qemu like this:</p>
<pre><code>qemu -hda myos.vmdk -cdrom myrinix-kde-200808.iso -m 512 -boot d</code></pre>
<p>After I have done the installation, I will boot up my guest OS from disk image like this:<br />
( You may want to point your cdrom to physical cdrom as well as enable USB.)</p>
<pre><code>qemu -hda myos.vmdk -cdrom /dev/cdrom -m 512 -usb -boot c</code></pre>
<p>qemu-img allows me to convert disk image too, in case I have downloaded image disk from somewhere, I can convert it to vmdk like this:</p>
<pre><code>qemu-img convert -f qcow freebsd.qcow -O freebsd.vmdk</code></pre>
<p>To load up image disk with vmware, I need another file, with extension of .vmx. Vmx file is a text file that contains configuration for your disk image. To generate one using <a href="http://www.easyvmx.com/">http://www.easyvmx.com/</a>. Remember to point your disk image to <em>ide0:0.filename</em> in vmx, for example my case:</p>
<pre><code>ide0:0.fileName = "freebsd.vmdk"
</code></pre>
<p><strong>Performance</strong><br />
It seems even with kqemu, qemu performance in terms of execution speed is still slower than vmware. I compare the same disk image in both vmware server as well as qemu. It will be obvious when I access the GUI menu in my guest OS.</p>
<p>There are still a lots of options and tips I fails to covers here, in case you have any tips, please feel no hesitate to leave me comments.</p>
<div class="aizatto_related_posts"><span class="aizatto_related_posts_header" >Related Posts</span><br/><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/438/experiencing-with-vmware-server-and-sun-xvm-virtualbox/" rel="bookmark" title="Permanent Link: Experiencing with vmware server and Sun xVM VirtualBox" >Experiencing with vmware server and Sun xVM VirtualBox</a></span><div class="aizatto_related_posts_excerpt">Recently I have tried Sun xVM VirtualBox 1.6.4 , I have compare vbox with Vmware server 1.0.4. After couple days of test...</div><p></p><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/334/help-yourself-in-python/" rel="bookmark" title="Permanent Link: Help yourself in python" >Help yourself in python</a></span><div class="aizatto_related_posts_excerpt">If your computer science student, you study IT, click with technology, python is not a snake for you. It is a scripting-...</div><p></p><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/340/how-to-generate-system-hardware-profile-for-your-laptop/" rel="bookmark" title="Permanent Link: How to generate system hardware profile for your laptop?" >How to generate system hardware profile for your laptop?</a></span><div class="aizatto_related_posts_excerpt">Recently, MIS department request us for hardware and software profile. They provide us Belarc Advisor (personal pc audit...</div><p></p></div>
<p><a href="http://feedads.googleadservices.com/~a/U8-rebGK27maM_smAW-icY5EoCI/a"><img src="http://feedads.googleadservices.com/~a/U8-rebGK27maM_smAW-icY5EoCI/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/LinuxByExamples/~4/YtQ3WKwe9Oo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://linux.byexamples.com/archives/424/virtualize-your-operating-system-with-qemu/feed/</wfw:commentRss>
		<feedburner:origLink>http://linux.byexamples.com/archives/424/virtualize-your-operating-system-with-qemu/</feedburner:origLink></item>
		<item>
		<title>Syslog: Sending log from remote servers to syslog daemon</title>
		<link>http://feedproxy.google.com/~r/LinuxByExamples/~3/aXToD7Xdwkc/</link>
		<comments>http://linux.byexamples.com/archives/412/syslog-sending-log-from-remote-servers-to-syslog-daemon/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 12:09:17 +0000</pubDate>
		<dc:creator>mysurface</dc:creator>
		
		<category><![CDATA[Admin]]></category>

		<category><![CDATA[logger]]></category>

		<category><![CDATA[nc]]></category>

		<category><![CDATA[rsyslogd]]></category>

		<category><![CDATA[syslogd]]></category>

		<category><![CDATA[tail]]></category>

		<guid isPermaLink="false">http://linux.byexamples.com/?p=412</guid>
		<description><![CDATA[syslog is a standard for logging service in Linux, it usually run as daemon like syslogd or rsyslogd. Syslog daemon will be forward and store logs in /var/log directory, you may configure it to store at separate location if you want. (we will look into it later). And there is a major file that store [...]]]></description>
			<content:encoded><![CDATA[<p><strong>syslog</strong> is a standard for logging service in Linux, it usually run as daemon like syslogd or rsyslogd. Syslog daemon will be forward and store logs in /var/log directory, you may configure it to store at separate location if you want. (we will look into it later). And there is a major file that store majority of logs, which is messages. Therefore, you may want to monitor linux messages logs by tailing /var/log/message.</p>
<p>Logs entry may come from various services, applications, kernel as well as remote servers if you enabled your syslog daemon to accept remote logs submissions. Syslog protocol is now standardized within the <a href="http://www.ietf.org/html.charters/syslog-charter.html">Syslog working group</a> of the IETF, and it is been defines in <a href="http://tools.ietf.org/html/rfc3164"> RFC 3164</a>.</p>
<p><a href="http://www.rsyslog.com/">Rsyslog</a> is an enhanced multi-threaded syslogd with a focus on security and reliability. I think newer linux distro already replace syslogd with rsyslogd. For more information you can check out the <a href="http://en.wikipedia.org/wiki/Syslog">wikipedia</a>.</p>
<p>In this post, I briefly explain the facility and log levels of syslog protocol, how to configure syslogd as well as rsyslogd to accept logs from remote and also how to send logs remotely.<br />
<span id="more-412"></span></p>
<p>Syslog categories logs into PRI which constructed by <strong>facility</strong> and <strong>severity/priority/log levels</strong>. </p>
<p><strong>Facility</strong> defines the source of the log entries, what kind of services that send this logs. Lets look at Facility info that extracted from RFC 3164, each facility was been assign a numeric code.</p>
<pre><code>
    Numerical       Facility
          Code
           0             kernel messages
           1             user-level messages
           2             mail system
           3             system daemons
           4             security/authorization messages
           5             messages generated internally by syslogd
           6             line printer subsystem
           7             network news subsystem
           8             UUCP subsystem
           9             clock daemon
          10             security/authorization messages
          11             FTP daemon
          12             NTP subsystem
          13             log audit
          14             log alert
          15             clock daemon
          16             local use 0  (local0)
          17             local use 1  (local1)
          18             local use 2  (local2)
          19             local use 3  (local3)
          20             local use 4  (local4)
          21             local use 5  (local5)
          22             local use 6  (local6)
          23             local use 7  (local7)
 </code></pre>
<p>Severity is the log levels that defines how critical of the log entries, from 0 - 7, 0 indicates the most critical and 7 is for debugging purpose. </p>
<pre><code>
    Numerical         Severity
          Code

           0       Emergency: system is unusable
           1       Alert: action must be taken immediately
           2       Critical: critical conditions
           3       Error: error conditions
           4       Warning: warning conditions
           5       Notice: normal but significant condition
           6       Informational: informational messages
           7       Debug: debug-level messages
</code></pre>
<p><strong>PRI</strong> is a unique values constructed by facility and severity where severity takes 3 LSB (least significant bits) append with facility start from bit 4.</p>
<pre><code>PRI = (facility &lt;&lt; 3) + severity </code></pre>
<p>&lt;&lt; indicates left shift which I borrow it from c++ programming language, when I do left shift N its like multiply with 2^N(two to the power of N). In this context, PRI formula can be written as</p>
<pre><code>PRI = (facility * 2^3) + severity </code></pre>
<p>PRI is important when you wanna send message to syslog, the default message PRI is user(1).notice(5) which the PRI value is 8 + 5 = 13. Meaning if you do not specified the PRI value, it will be treated as 13. </p>
<p>For common Linux distro, syslogd or rsyslogd should be started before you login to your system, you can verify that with ps.</p>
<pre><code>ps aux| grep syslogd</code></pre>
<p>Usually syslogd comes with distro does not configured to accept remote messages, unless -r is specified.</p>
<pre><code>root      4232  0.0  0.0  13424   888 ?        Sl   Jul22   0:00 syslogd -m 0 -r</code></pre>
<p><strong>How to enable syslogd to accept remote message?</strong><br />
syslog will listening to UDP port 514 for messages sent remotely, but if your distro running rsyslogd, you can listen to TCP port and you may also need to specify the port number.</p>
<p>Different Linux distro may have different ways of configuration, let say if you are using Red hat based distro, your syslogd and rsyslogd configuration will be at /etc/sysconfig/syslog or /etc/sysconfig/rsyslog. </p>
<p>For the case of rsyslogd, change the SYSLOGD_OPTIONS in /etc/sysconfig/rsyslog from SYSLOGD_OPTIONS=&#8221;-m 0&#8243; to <strong>SYSLOGD_OPTIONS=&#8221;-m 0 -r514&#8243;</strong> for UDP and SYSLOGD_OPTIONS=&#8221;-m 0 -t514&#8243; for TCP. For the case of syslogd, change it to <strong>SYSLOGD_OPTIONS=&#8221;-m 0 -r&#8221;</strong>.</p>
<p>After that, restart your syslog or rsyslog services, In Fedora or Red Hat, you may do this with root permission.</p>
<pre><code>service syslog restart</code></pre>
<p>Or you can just kill the syslogd process and start manually from console for testing.</p>
<pre><code>rsyslogd -m 0 -r514</code></pre>
<p><strong>Syslog Configurations</strong><br />
syslog daemon includes a configuration files to specified which logs to keep and append it to which file based on the PRI stated above.</p>
<p>Below are the sample of /etc/rsyslog.conf</p>
<pre><code>
# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none        /var/log/messages

# The authpriv file has restricted access.
authpriv.*                                                    /var/log/secure

# Log all the mail messages in one place.
mail.*                                                         /var/log/maillog

# Log cron stuff
cron.*                                                       /var/log/cron
</code></pre>
<p>You defines what messages goes to what file like this:</p>
<pre><code>facility.severity         log_files</code></pre>
<p>For example:</p>
<pre><code>user.notice              /var/log/user.notice</code></pre>
<p>The line above indicates that, when I get syslog message with facility user and severity notice, it will be append to file /var/log/user.notice. </p>
<p>For more info, please check out <a href="http://www.precision-guesswork.com/sage-guide/syslog-overview.html">here</a>.</p>
<p><strong>How to send message to syslogd?</strong><br />
For sending locally, we can use the <a href="http://linux.byexamples.com/archives/category/admin/logger/">logger</a> command. Before you send the message to syslog, lets tail the message log.</p>
<pre><code>tail -f /var/log/messages</code></pre>
<p>Now send &#8220;hello world&#8221; with logger.</p>
<pre><code>logger "hello world"</code></pre>
<p>It will appear in <strong>/var/log/messages</strong> as well as <strong>/var/log/user.notice</strong> if you have configure syslog.conf to forward user.notice messages to /var/log/user.notice. This proves that the default message&#8217;s PRI is user.notice. You may assign different PRI value to logger. For example if I wanna send message with PRI = user.info:</p>
<pre><code>logger -p user.info "testing 123"</code></pre>
<p><strong>How to send log message to remote server?</strong><br />
Unfortunately, you can&#8217;t send through logger. But you can manually send a plain text UDP package to remote servers that listening on UDP port 514. With the help of netcat(nc), we can send the message to remote syslogd as simple as logger command.</p>
<pre><code>nc -w0 -u 192.168.1.1 514 &lt;&lt;&lt; "logging from remote"</code></pre>
<p>To assign your message a PRI, you need to specified PRI&#8217;s value in numeric.<br />
User.Info&#8217;s PRI value is:<br />
 (1 << 3 ) + 6 = 8 + 6 = 14. ( refers back the numerical code of facility and severity )</p>
<pre><code>nc -w0 -u 192.168.1.1 514 &lt;&lt;&lt; "&lt;14&gt;User Info msg from remote"</code></pre>
<p>If your rsyslogd are listening to TCP port, just ignore -w0 and -u:</p>
<pre><code>nc 192.168.1.1 514 &lt;&lt;&lt; "&lt;14&gt;User Info msg from remote through TCP."</code></pre>
<div class="aizatto_related_posts"><span class="aizatto_related_posts_header" >Related Posts</span><br/><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/34/secure-file-transfer-through-ssh/" rel="bookmark" title="Permanent Link: secure file transfer through ssh" >secure file transfer through ssh</a></span><div class="aizatto_related_posts_excerpt">If you want to transfer one or few files which you have know the location, scp would be enough. SCP example will be HERE...</div><p></p><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/32/a-secure-way-to-access-remote-site/" rel="bookmark" title="Permanent Link: a secure way to access remote site" >a secure way to access remote site</a></span><div class="aizatto_related_posts_excerpt">If you are working at under unix/linux environment, you must know how to ssh. SSH can be consider a secure way to access...</div><p></p><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/311/sending-http-post-using-curl-command/" rel="bookmark" title="Permanent Link: sending HTTP POST using curl command" >sending HTTP POST using curl command</a></span><div class="aizatto_related_posts_excerpt">Recently I was having fun with libcurl, discovered that with curl command I capable of doing HTTP POST with specified Us...</div><p></p></div>
<p><a href="http://feedads.googleadservices.com/~a/LUiw-Q2e9qGceAzOhybnLXDqHJw/a"><img src="http://feedads.googleadservices.com/~a/LUiw-Q2e9qGceAzOhybnLXDqHJw/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/LinuxByExamples/~4/aXToD7Xdwkc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://linux.byexamples.com/archives/412/syslog-sending-log-from-remote-servers-to-syslog-daemon/feed/</wfw:commentRss>
		<feedburner:origLink>http://linux.byexamples.com/archives/412/syslog-sending-log-from-remote-servers-to-syslog-daemon/</feedburner:origLink></item>
		<item>
		<title>Top Ten Processes Watcher</title>
		<link>http://feedproxy.google.com/~r/LinuxByExamples/~3/yHuv1oM33A4/</link>
		<comments>http://linux.byexamples.com/archives/411/top-ten-processes-watcher/#comments</comments>
		<pubDate>Sun, 13 Jul 2008 14:51:32 +0000</pubDate>
		<dc:creator>mysurface</dc:creator>
		
		<category><![CDATA[head]]></category>

		<category><![CDATA[tail]]></category>

		<category><![CDATA[top]]></category>

		<category><![CDATA[watch]]></category>

		<guid isPermaLink="false">http://linux.byexamples.com/?p=411</guid>
		<description><![CDATA[top command provides a dynamic real-time view of a running system. It can display system summary information as well as a list of tasks currently being managed by the Linux kernel. But if you want get something more specific, you must play some tricks on it. For example, I want a clean view of top [...]]]></description>
			<content:encoded><![CDATA[<p><i>top</i> command provides a dynamic real-time view of a running system. It can display system summary information as well as a list of tasks currently being managed by the Linux kernel. But if you want get something more specific, you must play some tricks on it. For example, I want a clean view of top ten busiest processes every seconds without those summary info, how should I do with top?</p>
<p><b>Batch mode operation</b><br />
top is a real-time application that keeps display processes info sorted by cpu usage, if you redirects the outputs to a file like command line below, you will having your results mixed with ugly symbols, which is not what you want.</p>
<pre><code>top &gt; top.txt</code></pre>
<p>Well, top support batch mode. By specified top on batch mode, top will display the outputs without arrange the views properly, but if you redirects it to a file, you won&#8217;t get those messy symbols mixed up.</p>
<pre><code>top -b &gt; top.txt</code></pre>
<p><b>I just want to monitor top ten processes every seconds!</b><br />
You can limits your views of top ten using <i>head</i> and <i>tail</i>, but this will STOP top from continuing to monitor the processes.</p>
<pre><code>top -d 1 | head -n 17 | tail -n 11</code></pre>
<p>Fortunately, we have <i>watch</i> to help, but you needs to put top in batch mode, and also you can ask top to stop after done displaying the result for one time. This will increase the accuracy of the result.</p>
<pre><code>watch -n 1 "top -b -n 1 | head -n 17 | tail -n 11"</code></pre>
<div class="aizatto_related_posts"><span class="aizatto_related_posts_header" >Related Posts</span><br/><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/158/how-to-check-the-cpu-and-mem-usage-of-current-running-process/" rel="bookmark" title="Permanent Link: how to check the CPU and mem usage of current running process?" >how to check the CPU and mem usage of current running process?</a></span><div class="aizatto_related_posts_excerpt">We may curious some times why our computer running so slow, and we suspect that must be some programs (process) is runni...</div><p></p><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/144/redirect-output-to-multiple-processes/" rel="bookmark" title="Permanent Link: Redirect output to multiple processes" >Redirect output to multiple processes</a></span><div class="aizatto_related_posts_excerpt">Since tee can read the standard input, and write to multiple files, we may leverage this feature so that it writes to mu...</div><p></p><span class="aizatto_related_posts_title" ><a href="http://linux.byexamples.com/archives/242/monitor-custom-programs-with-ps-and-watch/" rel="bookmark" title="Permanent Link: monitor custom programs with ps and watch" >monitor custom programs with ps and watch</a></span><div class="aizatto_related_posts_excerpt">ps is a very useful tool to list all current running processes with various info such as CPU usage, memory usage, proces...</div><p></p></div>
<p><a href="http://feedads.googleadservices.com/~a/MLHhS1OFPGULZ_PdE5HPJzgll7E/a"><img src="http://feedads.googleadservices.com/~a/MLHhS1OFPGULZ_PdE5HPJzgll7E/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/LinuxByExamples/~4/yHuv1oM33A4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://linux.byexamples.com/archives/411/top-ten-processes-watcher/feed/</wfw:commentRss>
		<feedburner:origLink>http://linux.byexamples.com/archives/411/top-ten-processes-watcher/</feedburner:origLink></item>
	</channel>
</rss>
