<?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>Joyce Babu &#187; Linux / Unix</title>
	<atom:link href="http://www.joycebabu.com/blog/category/unix/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.joycebabu.com</link>
	<description>Read, learn and share.</description>
	<lastBuildDate>Sun, 25 Jul 2010 10:32:51 +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>View currently running MySQL queries in realtime</title>
		<link>http://www.joycebabu.com/blog/view-currently-running-mysql-queries-in-realtime.html</link>
		<comments>http://www.joycebabu.com/blog/view-currently-running-mysql-queries-in-realtime.html#comments</comments>
		<pubDate>Sun, 18 Jul 2010 08:36:47 +0000</pubDate>
		<dc:creator>Joyce</dc:creator>
				<category><![CDATA[Linux / Unix]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Solr]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.joycebabu.com/?p=261</guid>
		<description><![CDATA[Sometimes you might want to view MySQL queries as and when they are being executed. This is possible with the MySQL General Query Log. In this post, I try to explain how to use query logging feature to view live running MySQL queries.]]></description>
			<content:encoded><![CDATA[<p>Today I was playing around with <a href="en.wikipedia.org/wiki/Apache_Solr" target="_blank">Apache Solr</a>. I was really impressed by its text searching capability, especially the <a href="http://wiki.apache.org/solr/MoreLikeThisHandler" target="_blank">MoreLikeThis</a> search handler. I wanted to configure the <a href="http://wiki.apache.org/solr/DataImportHandler" target="_blank">DataImportHandler</a> to import data directly from my MySQL database. It was really easy to configure, and I was able to perform a full import quickly. But when I tried to do a delta import, I found that it was not working as expected. Even though I was calling the delta import, it was causing a full import.</p>
<p>You might be wondering  why I am saying all these here. Well, I suspected that the problem was actually because of my SQL query for delta load.  But to be sure, I wanted to see the query being executed by Solr DataImportHandler. As always I turned to Google for assistance, and I finally reached the MySQL documentation on the <a title="General Query Log" href="http://dev.mysql.com/doc/refman/5.1/en/query-log.html" target="_blank">General Query Log</a>. Voila! This was exactly what I wanted. All I had to do was use the &#8211;log=[filename] parameter and all my queries will be logged to the specified log file. Nice, isn&#8217;t it?</p>
<p>Now I have to stop my running MySQL server and restart it with the &#8211;log switch, in addition to the other regular options. But there was a problem, I was not sure of the other required parameters. You can use the ps utility, when the MySQL server is running, to find out the normal parameters.</p>
<p><code>ps -ax | grep mysql</code></p>
<p>For me the output was</p>
<p><em>/usr/local/mysql/bin/mysqld &#8211;basedir=/usr/local/mysql &#8211;datadir=/usr/local/mysql/data &#8211;user=mysql &#8211;pid-file=/usr/local/mysql/data/localhost.pid &#8211;port=3306 &#8211;socket=/tmp/mysql.sock</em></p>
<p>Now shutdown the MySQL server.</p>
<p><code>// On Mac<br />
/Library/StartupItems/MySQLCOM/MySQLCOM stop</code><br />
<code>// For other Linux/Unix variants try<br />
/etc/init.d/mysqld restart<br />
service mysql restart</code></p>
<p>Start mysqld with <em>&#8211;log</em> option</p>
<p><code>/usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql  --datadir=/usr/local/mysql/data --user=mysql  --pid-file=/usr/local/mysql/data/localhost.pid --port=3306  --socket=/tmp/mysql.sock --log=/tmp/query.log</code></p>
<p>The general query log contains lots of irrelevant information. To view the log after filtering out the unwanted details use tail and grep as given below</p>
<p><code>tail -f /tmp/query.log | grep -v Connect | grep -v Quit</code></p>
<p>The amount of information added to the file is quite large. If you are using this on a production server, I recommend turning off the logging once you are done.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joycebabu.com/blog/view-currently-running-mysql-queries-in-realtime.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Split header and footer into separate files using awk</title>
		<link>http://www.joycebabu.com/blog/split-header-and-footer-into-separate-files-using-awk.html</link>
		<comments>http://www.joycebabu.com/blog/split-header-and-footer-into-separate-files-using-awk.html#comments</comments>
		<pubDate>Tue, 20 Apr 2010 04:51:06 +0000</pubDate>
		<dc:creator>Joyce</dc:creator>
				<category><![CDATA[Linux / Unix]]></category>
		<category><![CDATA[AWK]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[Scripting languages]]></category>
		<category><![CDATA[Shell Scripting]]></category>

		<guid isPermaLink="false">http://www.joycebabu.com/?p=249</guid>
		<description><![CDATA[Saving header and footer from a file into separate files using AWK.]]></description>
			<content:encoded><![CDATA[<p>Recently I had to write a shell script to read a file and split it into header and footer. The header and footer were to be saved into different files. At first I decided to write a script to loop through the file and save the content after performing the necessary condition check. But later I decided that this is not the best solution and checked whether there was a single line command for the same. As usual, I found a simple solution to the problem with awk.</p>
<blockquote><p><code>awk '{if (NR == 1)print &gt;&gt; "header.txt"; else print &gt;&gt; "body.txt";}' input.txt</code><br />
<span style="color: #808080;"><em>Where NR is a built-in variable that contains the number of the current record / line,<br />
input.txt is the input file,<br />
header.txt is output file for header,<br />
body.txt is the output file for the remaining content</em></span></p></blockquote>
<p>Awk reads the input file (input.txt) line by line and checks whether the current line is the first line. If so the content is appended ( &gt;&gt; ) to the file header.txt. Else the content is appended to body.txt.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joycebabu.com/blog/split-header-and-footer-into-separate-files-using-awk.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Saving wget file with different filename</title>
		<link>http://www.joycebabu.com/blog/saving-wget-file-with-different-filename.html</link>
		<comments>http://www.joycebabu.com/blog/saving-wget-file-with-different-filename.html#comments</comments>
		<pubDate>Mon, 04 Jan 2010 11:05:44 +0000</pubDate>
		<dc:creator>Joyce</dc:creator>
				<category><![CDATA[Linux / Unix]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[save]]></category>
		<category><![CDATA[wget]]></category>

		<guid isPermaLink="false">http://www.joycebabu.com/?p=175</guid>
		<description><![CDATA[Anyone who has worked with Linux must be familar with the wget utility. wget utility allows you to download files from a remote server using HTTP, HTTPS and FTP protocols. Downloading files using wget is as simple as wget http://www.joycebabu.com/my-photo.jpg Where http://www.joycebabu.com/my-photo.jpg is the file to be downloaded. By default wget saves the file with [...]]]></description>
			<content:encoded><![CDATA[<p>Anyone who has worked with Linux must be familar with the <em>wget </em>utility. <em>wget </em>utility allows you to download files from a remote server using HTTP, HTTPS and FTP protocols. Downloading files using <em>wget </em>is as simple as</p>
<blockquote><p><code>wget http://www.joycebabu.com/my-photo.jpg</code><br />
<span style="color: #888888;"><em>Where http://www.joycebabu.com/my-photo.jpg is the file to be downloaded.</em></span></p></blockquote>
<p>By default <em>wget </em>saves the file with the same name as the fetched file. For example, the above command will save the file as <em>my-photo.jpg</em> in the current working directory. If a file already exists with the given name, the downloaded file will be named as <em>my-photo.jpg.1</em>, <em>my-photo.jpg.2</em> etc until a non existent filename is found.</p>
<p>It is possible to explicitly specify a different name for the downloaded file. This is possible using the <code>-O</code> switch (<code>--output-document</code> also works, but I believe short is sweet). The new command is</p>
<blockquote><p><code>wget -O photo.jpg http://www.joycebabu.com/my-photo.jpg</code><br />
<span style="color: #888888;"><em>Where photo.jpg is the new filename.</em></span></p></blockquote>
<p><strong>But be careful while using the <code>-O</code> switch. If there is an existing file with the same name, it will be overwritten with the new file.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.joycebabu.com/blog/saving-wget-file-with-different-filename.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Copying multiple files simultaneously using scp utility</title>
		<link>http://www.joycebabu.com/blog/copying-multiple-files-with-scp.html</link>
		<comments>http://www.joycebabu.com/blog/copying-multiple-files-with-scp.html#comments</comments>
		<pubDate>Fri, 01 Jan 2010 15:45:01 +0000</pubDate>
		<dc:creator>Joyce</dc:creator>
				<category><![CDATA[Linux / Unix]]></category>
		<category><![CDATA[copy files]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[multiple files]]></category>
		<category><![CDATA[scp]]></category>
		<category><![CDATA[secure copy]]></category>

		<guid isPermaLink="false">http://www.joycebabu.com/?p=155</guid>
		<description><![CDATA[How to copy multiple files using the Secure Copy (scp) utility.]]></description>
			<content:encoded><![CDATA[<p>Happy New Year to all.</p>
<p>I have been using the Secure Copy (scp) utility for copying files between my local server and development server. Sometimes I have to copy more than one file. Previously I used to copy the files one at a time. This is very annoying, as you have to type the password every time you use the command . But it is possible to copy multiple files using scp, just like the copy (cp) utility.</p>
<p>When you have to copy multiple files to your remote server, the syntax is similar to the cp command.</p>
<blockquote><p><code>scp file1.sql file2.sh joyce@joycebabu.com:~/upload</code></p></blockquote>
<p>Where file1.sql and file2.sh are the files to be copied, joyce is the username, joycebabu.com is the hostname and ~/upload is the destination directory on the remote server.</p>
<p>In order to download multiple files from the remote server, the command to be used is</p>
<blockquote><p><code>scp joyce@joycebabu.com:"file1.log file2.log" ~/logs</code></p></blockquote>
<p>Where file1.log and file2.log are the files to be downloaded and ~/logs is the destination directory on the local server. Notice the quotes around the filenames. This ensures that the filenames list is not parsed by the local shell and is passed to the remote shell. Similarly, when you want to download files using wildcards (*.php, files_?.log etc), you should enclose the name within quotes to ensure that the expansion is done by the remote server.</p>
<p>The -r option can be used to copy directories recursively.</p>
<blockquote><p><code>scp -r joyce@joycebabu.com:~/logs ~/logs</code></p></blockquote>
<p>This may not be a lifesaver tip and the time gained by this method may be small. After all, when a large number of files are to be transferred, I use FTP or tar my files and copy it. But at times when things go wrong, even this small gain can help.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joycebabu.com/blog/copying-multiple-files-with-scp.html/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Extract single table from a mysql dump</title>
		<link>http://www.joycebabu.com/blog/extract-single-table-from-a-mysql-dump.html</link>
		<comments>http://www.joycebabu.com/blog/extract-single-table-from-a-mysql-dump.html#comments</comments>
		<pubDate>Wed, 15 Jul 2009 17:27:12 +0000</pubDate>
		<dc:creator>Joyce</dc:creator>
				<category><![CDATA[Linux / Unix]]></category>
		<category><![CDATA[AWK]]></category>
		<category><![CDATA[Extract Table]]></category>
		<category><![CDATA[Grep]]></category>
		<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL Backup]]></category>
		<category><![CDATA[Sed]]></category>

		<guid isPermaLink="false">http://www.joycebabu.com/?p=144</guid>
		<description><![CDATA[Extracting single table from a huge mysqldump file using unix shell commands.]]></description>
			<content:encoded><![CDATA[<p>The other day, while working with the MySQL database of one of my sites, I accidentally damaged one of the tables irrecoverably. Fortunately, I was using <a href="http://sourceforge.net/projects/automysqlbackup/" target="_blank">AutoMySQLBackup</a> script to backup all my databases at 12 AM every day. To save time, I decided to import only the damaged table. But when I tried to open the .sql file created by the mysqldump program, I understood that it was not going to as easy as I thought. The dump file was over 100 MB in size and  none of my text editors allowed me to open a file of that size.</p>
<p>As usual, I approached Google for a solution and it introduced me to two different solutions &#8211; AWK (a programming language) and Sed (a unix utility). There is only a very slight difference between the two commands.</p>
<blockquote><p>awk &#8216;/&#8211; Table structure for table .tbl_first./,/&#8211; Table structure for table .tbl_second./{print}&#8217; mydumpfile.sql &gt; mytable.sql</p>
<p>sed -ne &#8216;/&#8211; Table structure for table .tbl_first./,/&#8211; Table structure for table .tbl_second./p&#8217; mydumpfile.sql &gt; mytable.sql</p></blockquote>
<p>Here <em>tbl_first</em> is the table I wanted to extract and <em>tbl_second</em> was the table below that. The above commands will search the file <em>mydumpfile.sql</em> and extract the text between the start string (<em>&#8211; Table structure for table .tbl_first.</em>) and end string (<em>&#8211; Table structure for table .tbl_second.).</em> The dots before and after the table name are wildcard character to match the engrave character, which has a special meaning in shell commands. The {print} option (p in sed) prints the extracted string, which is then redirected to the file <em>mytable.sql</em>.</p>
<p>But that didn&#8217;t solve my problem completely. I was not sure of the order of tables in the .sql file. This time  <em>grep</em> (another powerful unix utility) came to my rescue. The following command lists all the tables in the file <em>mydumpfile.sql</em> in the same order in which they appear in the file.</p>
<blockquote><p>grep &#8216;Table structure&#8217; mydumpfile.sql | cut -d&#8217;`&#8217; -f2</p></blockquote>
<p>I don&#8217;t know a lot about shell commands. But with my very limited experience I can say that they are extremely powerful. Two small lines of code saved me a lot of time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joycebabu.com/blog/extract-single-table-from-a-mysql-dump.html/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
