<?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>Lindesk &#187; Programming</title>
	<atom:link href="http://lindesk.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://lindesk.com</link>
	<description>Linux - on the Desktop</description>
	<lastBuildDate>Tue, 19 Jan 2010 05:54:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Perl Script to Backup MySQL Databases</title>
		<link>http://lindesk.com/2008/06/perl-script-to-backup-mysql-databases/</link>
		<comments>http://lindesk.com/2008/06/perl-script-to-backup-mysql-databases/#comments</comments>
		<pubDate>Thu, 19 Jun 2008 17:55:59 +0000</pubDate>
		<dc:creator>BinnyVA</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Shell Scripts]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://lindesk.com/?p=113</guid>
		<description><![CDATA[A perl script that can be used to backup your databases.]]></description>
			<content:encoded><![CDATA[<p class="intro">So far, we covered <a href="http://lindesk.com/2008/05/shell-script-to-backup-files-locally-using-rsync/">backing up files locally</a> and <a href="http://lindesk.com/2008/06/script-to-backup-files-over-a-network-using-rsync/">over a network</a>. Now let let see how to backup databases(only mysql supported &#8211; yet).</p>
<p>The <strong class="highlight">script uses &#8216;mysqldump&#8217;</strong> command to backup the data. That means that the <strong class="highlight">backups are in the SQL dump format</strong>. The dumps of all the databases that are backed up are compressed and stored in the destination folder. They will be named in this format &#8211; YYYY-MM-DD.tar.gz.</p>
<h2>Configuration File</h2>
<p>This script <strong class="highlight">reads a configuration file named &#8216;dbbackup.config&#8217; and backups all the databases specified in that file</strong> to another location in the same system. This <strong class="highlight">configuration file must be in the same folder as the perl script</strong>. The configuration file format is given below&#8230;</p>
<pre><code class="text">Data
Project_Nexty
App_activecollab
# Unwanted_DB - commented - will not be backedup
binco
binnyva
</code></pre>
<h2>The Perl Script</h2>
<pre><code class="perl">
#!/usr/bin/perl
# Backups all the databases specified in the dbbackup.config file

$backup_folder = '/var/Backup/Special/Databases'; #EDIT THIS LINE

use File::Basename;
my $config_file = dirname($0) . "/dbbackup.config";
my @databases = removeComments(getFileContents($config_file));

chdir($backup_folder) or die("Cannot go to folder '$backup_folder'");

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year += 1900;
$mon++;
#Zero padding
$mday = '0'.$mday if ($mday&lt;10);
$mon = '0'.$mon if ($mon&lt;10);

my $folder = "$year-$mon-$mday";
mkdir($folder) or die("Cannot create a folder called '$folder'");

foreach my $database (@databases) {
	next if ($database eq '');
	chomp($database);

	my $table = '';
	if(index($database,' ')+1) { #Get just 1 table in the database - if there is a ' '(space) in the db name
		my @parts = split(' ',$database);
		$database = $parts[0];
		$table = $parts[1];
	}

	print "Backing up $database ... ";

 	my $file = $database;
 	$file .= '_' . $table if($table ne '');
 	$file .= ".sql";

 	`mysqldump -u root $database $table &gt; $folder/$file`;

	print "Done\n";
}
print "Compressing the folder ... ";
`tar -czf $folder.tar.gz $folder/`;
print "Done\nRemoving Folder ... ";
`rm -rf $folder`;
print "Done\n\n";

sub getFileContents {
	my $file = shift;
	open (FILE,$file) || die("Can't open '$file': $!");
	my @lines=&lt;FILE&gt;;
	close(FILE);

	return @lines;
}

sub removeComments {
	my @lines = @_;

	@cleaned = grep(!/^\s*#/, @lines); #Remove Comments
	@cleaned = grep(!/^\s*$/, @cleaned); #Remove Empty lines

	return @cleaned;
}
</code></pre>
<p>If you need, you can set this script as a cron job &#8211; this will make sure that you don&#8217;t have to worry about the backup.</p>
]]></content:encoded>
			<wfw:commentRss>http://lindesk.com/2008/06/perl-script-to-backup-mysql-databases/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Shell Script to Backup Files Locally Using Rsync</title>
		<link>http://lindesk.com/2008/05/shell-script-to-backup-files-locally-using-rsync/</link>
		<comments>http://lindesk.com/2008/05/shell-script-to-backup-files-locally-using-rsync/#comments</comments>
		<pubDate>Fri, 09 May 2008 18:21:35 +0000</pubDate>
		<dc:creator>BinnyVA</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Shell Scripts]]></category>
		<category><![CDATA[automate]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[rsync]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://lindesk.com/?p=108</guid>
		<description><![CDATA[All programmers have their own customized backup solutions. I have six. Yes, six! Five to backup files and one to backup database tables. And I am not counting version control or other backup systems built into the tools I use. Anyway, in the first post of the shell scripts series, let me introduce you to [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://lindesk.com/wp-content/uploads/2008/02/terminal.png" alt="Terminal" title="Terminal" width="128" height="128" class="intro size-full wp-image-96" align="right" /></p>
<p class="intro">All programmers have their own customized backup solutions. I have six. Yes, six! Five to backup files and one to backup database tables. And I am not counting version control or other backup systems built into the tools I use. Anyway, in the first post of the <a href="http://lindesk.com/2008/05/shell-script-language-use-perl-not-bash/">shell scripts series</a>, let me introduce you to my Rsync based local backup solution.</p>
<h2>Configuration File</h2>
<p>This script <strong>reads a configuration file named &#8216;rsyncbackup.config&#8217;</strong> and backups all the folders specified in that file to <strong>another location in the same system</strong>. This configuration file must be in the same folder as the perl script. The configuration file format is given below&#8230;</p>
<pre><code class="text">#Notes - do NOT include the last '/' at the end of the source folders
~/Scripts
~/Documents

#################### Web files ####################
# My Sites
#Folder to backup		#Folder to which it should be backuped to
/var/www/html/Sites		Htdocs/
/var/www/html/Projects	Htdocs/</code></pre>
<p>If there is just one column in a line, that folder will be backuped to &#8220;<code>&lt;backup folder&gt;/&lt;folder name&gt;</code>&#8220;. Let say that my backup destination folder is &#8216;<code>/var/Backup/Rsync</code>&#8216;. So the first line, &#8216;<code>~/Scripts</code>&#8216; will copy the contents of &#8216;<code>~/Scripts</code>&#8216; to &#8216;<code>/var/Backup/Rsync/Scripts</code>&#8216;</p>
<p>If a line in the configuration file has two columns, then an extra folder will be created with the name provided in the second column. For example, the line &#8216;<code>/var/www/html/Sites &nbsp; &nbsp; Htdocs/</code>&#8216; will create a backup of &#8216;<code>/var/www/html/Sites</code>&#8216; in &#8216;<code>/var/Backup/Rsync/Htdocs/Sites</code>&#8216;</p>
<p>And if you have not guessed it already, all lines that begin in a # are comments and will be ignored.</p>
<h2>The Script</h2>
<p>There is the perl script that automates the rsync calls&#8230;</p>
<pre><code class="perl">#!/usr/bin/perl

#EDIT THIS LINE
$backup_folder = '/var/Backup/Rsync'; #Final '/' must NOT be there.

use File::Basename;
my $config_file = dirname($0) . "/rsyncbackup.config";
my @all_locations = removeComments(getFileContents($config_file));

chdir($backup_folder) or die("Cannot go to folder '$backup_folder'");

foreach my $folder_locations (@all_locations) {
	my($folder,$backup_location) = split(/\s+/,$folder_locations);

	print "Backing up $folder to $backup_location ... ";
	`rsync -a $folder $backup_folder/$backup_location`;
	print "Done\n";
}

sub getFileContents {
	my $file = shift;
	my @lines;
	if(!open (FILE,$file)) {
		die("Can't open '$file': $!");
	} else {
		@lines=&lt;FILE&gt;;
		close(FILE);
	}
	return @lines;
}

sub removeComments {
	my @lines = @_;

	@cleaned = grep(!/^\s*#/, @lines); #Remove Comments
	@cleaned = grep(!/^\s*$/, @cleaned); #Remove Empty lines

	return @cleaned;
}</code></pre>
<p>Execute this script using the command &#8216;perl RsyncBackup.pl&#8217;. In my system I have created an alias &#8216;bk&#8217; for this script. I recommend that you make a similar alias if you take backups regularly(extremely recommended).</p>
<p>Backing up is done using rsync &#8211; so its faster than a simple &#8216;cp&#8217; as only the modified and new files are copied.</p>
]]></content:encoded>
			<wfw:commentRss>http://lindesk.com/2008/05/shell-script-to-backup-files-locally-using-rsync/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Shell Script Language &#8211; Use Perl, Not Bash</title>
		<link>http://lindesk.com/2008/05/shell-script-language-use-perl-not-bash/</link>
		<comments>http://lindesk.com/2008/05/shell-script-language-use-perl-not-bash/#comments</comments>
		<pubDate>Fri, 02 May 2008 18:22:17 +0000</pubDate>
		<dc:creator>BinnyVA</dc:creator>
				<category><![CDATA[Command Line]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Opinion]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://lindesk.com/?p=107</guid>
		<description><![CDATA[To me, a shell script is a script that automates repetitive tasks. But that is not the &#8216;official&#8217; definition. Wikipedia has this definition&#8230; A shell script is a script written for the shell, or command line interpreter, of an operating system. I use a definition that defines the purpose of the script &#8211; while the [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://lindesk.com/wp-content/uploads/2008/02/terminal.png'><img src="http://lindesk.com/wp-content/uploads/2008/02/terminal.png" alt="" title="Terminal" width="128" height="128" class="alignnone intro size-full wp-image-96" align="right" /></a></p>
<p class="intro">To me, a shell script is a <strong class="highlight">script that automates repetitive tasks</strong>. But that is not the &#8216;official&#8217; definition. Wikipedia has this <a href="http://en.wikipedia.org/wiki/Shell_scripts">definition</a>&#8230;</p>
<blockquote cite="http://en.wikipedia.org/wiki/Shell_scripts"><p>A shell script is a script written for the shell, or command line interpreter, of an operating system.</p></blockquote>
<p>I use a definition that <strong class="highlight">defines the purpose</strong> of the script &#8211; while the others prefer a definition that <strong class="highlight">defines the technology used</strong>. I am not going to claim that my definition is better than the other definition &#8211; that&#8217;s pointless. Besides, even I think that the &#8216;other&#8217; definition is the right one. But I will try to show you the advantages of my approach.</p>
<h2>The Purpose</h2>
<p>I like to automate things(in other words, I&#8217;m lazy). So I have a nice little collection of custom shell scripts. But there is a huge barrier to writing shell scripts &#8211; the language used. <strong class="highlight">Traditionally shell scripts are written in a language provided by the shell</strong> &#8211; like <a href="http://www.gnu.org/software/bash/bash.html">bash</a> or <a href="http://www.tcsh.org/Welcome">tcsh</a>. That is the problem &#8211; these languages are Bad &#8211; with a capital &#8216;B&#8217;.</p>
<h2>The Problem</h2>
<p>To people who are accustomed to decent languages, these <strong class="highlight">shell languages will seem clunky</strong> &#8211; or even evil. But since most shell scripts are small, most people don&#8217;t mind the torture.</p>
<p>In bash, the control flow commands seem to be thrown in as a after thought rather than something that&#8217;s built into the language. If you don&#8217;t believe me, compare the &#8216;if&#8217; loop of bash and Perl.</p>
<h3>Bash</h3>
<p>This code checks wether the variable &#8216;$value&#8217; has the value 0 &#8211; if so it prints the message &#8216;No Value&#8217;</p>
<pre><code class="bash">if [ $value -eq 0 ] ; then
	echo "No Value"
fi</code></pre>
<h3>Perl</h3>
<p>The same code in Perl&#8230;</p>
<pre><code class="perl">if($value == 0) {
	print "No Value";
}</code></pre>
<p>Of course, Perl experts will go for <code>if(!$value)</code> or even <code>unless($value)</code> &#8211; but that&#8217;s not the point. See how better the <strong class="highlight">code looks in Perl</strong>. Yeah, even I am surprised to hear those words &#8211; Perl is considered by many to be an &#8216;ugly&#8217; language. But when compared to shell languages, Perl is a gem(sorry about the pun &#8211; couldn&#8217;t resist).</p>
<h2>The Solution</h2>
<p>The solution is simple &#8211; <strong class="highlight">don&#8217;t use a shell language to write your shell scripts &#8211; use a high level scripting language</strong> like Perl. Or Python, Ruby, PHP, Tcl or <a href="http://www.openjs.com/articles/javascript_scripting_language.php">even JavaScript</a>.</p>
<p>I still use <a href="http://www.openjs.com/articles/javascript_scripting_language.php" title="Command Line Twitter Client">bash to write shell scripts</a> &#8211; but if the shell script has an if condition(other than a simple argument check), I use a higher language &#8211; usually Perl.</p>
<h2>Advantages of using a Shell Language</h2>
<ul>
<li>Its supported in even the tinest linux distros &#8211; even in embedded systems.</li>
<li>Its the method preferred by the majority &#8211; I hope this will change soon.</li>
<li>Command calls look more natural in a shell language.</li>
</ul>
<h2>Advantages of using a High Level Language</h2>
<ul>
<li>Better Code</li>
<li>Easy to maintain</li>
<li>Faster development</li>
<li>Libraries provide a lot of functionality</li>
<li>Easier to port to different platforms.</li>
</ul>
<p>So why am I telling you all this? Two reasons&#8230;</p>
<p>One, the next time you are going to write a shell script, I want you to choose a high level language rather than using bash.</p>
<p>The second reason is that now that <a href="http://lindesk.com/2008/03/top-10-linux-mp3-players/">my series on Linux MP3 Players</a> are over, I am going to take a small break from desktop posts and write on more &#8216;linuxy&#8217; topics. And one of those topic is Shell Scripting. So in the future posts, I am going to share some of my shell scripts with you. So when I publish a Perl script and call it a shell script, I don&#8217;t want you to get confused .</p>
]]></content:encoded>
			<wfw:commentRss>http://lindesk.com/2008/05/shell-script-language-use-perl-not-bash/feed/</wfw:commentRss>
		<slash:comments>41</slash:comments>
		</item>
		<item>
		<title>Using Konqueror as an FTP Client</title>
		<link>http://lindesk.com/2007/05/using-konqueror-as-an-ftp-client/</link>
		<comments>http://lindesk.com/2007/05/using-konqueror-as-an-ftp-client/#comments</comments>
		<pubDate>Sat, 05 May 2007 11:20:46 +0000</pubDate>
		<dc:creator>BinnyVA</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[KDE]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://lindesk.com/2007/05/using-konqueror-as-an-ftp-client/</guid>
		<description><![CDATA[As a web developer good FTP clients are a necessity for me. I have to upload the scripts to the server. I used to use gFTP for this. Good client &#8211; clean interface, easy to use. But not as powerful as I wanted. Then I found FireFTP &#8211; the extension for Firefox &#8211; it is [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://lindesk.com/2007/04/konqueror-a-killer-app-for-linux/konqueror-logo/' rel='attachment wp-att-21' title='Konqueror Logo'><img class="intro" align="right" src='http://lindesk.com/wp-content/uploads/2007/04/konqueror.png' alt='Konqueror Logo' /></a></p>
<p class="intro">As a web developer good FTP clients are a necessity for me. I have to upload the scripts to the server. I used to use gFTP for this. Good client &#8211; clean interface, easy to use. But not as powerful as I wanted. Then I found FireFTP &#8211; the extension for Firefox &#8211; it is a good client. But recently I found that my favorite application, <strong class="highlight">Konqueror, can do it much better than all the other</strong> clients.</p>
<p>Didn&#8217;t know konqueror could be used as a FTP client? Just copy and paste this FTP URL into the address bar of Konqueror and see for yourself&#8230;<br />
<a href="ftp://checksoftware.com/">ftp://checksoftware.com/</a></p>
<h2>Advantages</h2>
<p>The main advantage of using Konqueror as the FTP client is that you are <strong class="highlight">very familiar with it</strong>. All the shortcuts, the tricks, you use when browsing through your files are available when you connect to a remote server as well. Ctrl+C and Ctrl+V? The FTP client has got it. What if you want to browse two folders in the remote server at the same time? Konqueror can do it.</p>
<h3>2 Pane View</h3>
<p>Like many other FTP Clients, you can <strong class="highlight">split Konqueror into two panes</strong>(Window-&gt;Split View Left and Right). This is perhaps the best way to use Konqueror as an FTP Client.</p>
<p><a href='http://lindesk.com/wp-content/uploads/2007/05/split_window.png' title='Konqueror using Split Window Interface'><img src='http://lindesk.com/wp-content/uploads/2007/05/split_window.thumbnail.png' alt='Konqueror using Split Window Interface' /></a></p>
<h3>X Pane View</h3>
<p>Unlike other FTP Clients, Konqueror goes further than just 2 panes. You can <strong class="highlight">keep on splitting a window</strong> to make it &#8216;just perfect&#8217; for you.</p>
<h3>Tabbed View</h3>
<p>If paned view is not enough, just open up a <strong class="highlight">new tab</strong> &#8211; and continue splitting it.</p>
<h3>Multiple Protocols &#8211; FTP/SFTP/FISH</h3>
<p><strong class="highlight">Konqueror supports many protocols</strong> &#8211; among which these three are the most important to us&#8230;</p>
<dl>
<dt>fish</dt>
<dd>You can use fish if you have a shell account on the remote server. For example, fish://admin@linkdesk.com would open a connection for user binnyva to a remote server &#8216;linkdesk.com&#8217;.</dd>
<dt>ftp</dt>
<dd>File Transfer Protocol &#8211; you should be knowing this if you have come this far <img src='http://lindesk.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </dd>
<dt>sftp</dt>
<dd>Secure FTP.</dd>
</dl>
<h2>Problems</h2>
<p>So far I have found only one issue with it &#8211; I was <strong class="highlight">not able to configure Konqueror to act as an FTP client properly when I was behind a proxy</strong>. I have reasons to believe that it was my fault &#8211; but I did spend some time trying. Could someone else confirm this?</p>
<h2>Conclusion</h2>
<p>Konqueror is the best FTP Client there is. Period.</p>
]]></content:encoded>
			<wfw:commentRss>http://lindesk.com/2007/05/using-konqueror-as-an-ftp-client/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

