find . -type f -exec perl -e 'rename($_, lc) || warn "$_: $!\n" for @ARGV' {} \;
Saturday, October 13, 2007
Perl : making all filenames lowercase
Wednesday, September 12, 2007
MySQL : root password reset
# stop mysql service
/etc/init.d/mysql stop
# Start to MySQL server w/o password
mysqld_safe --skip-grant-tables &
# Connect to mysql server using mysql client
mysql -u root
# Setup new MySQL root user password
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
# Stop MySQL Server
/etc/init.d/mysql stop
# Start MySQL server and test it
/etc/init.d/mysql start
mysql -u root -h localhost -p
Tuesday, September 04, 2007
Web Development : Saving sessions in database
1. The session data is more secure as a potential hacker must be
able to log into the database before he can access anything.
2. The use of multiple servers would not create a problem as all
session data now resides in a single central place and is accessible
by all servers.
3. It is much easier to query the database should the site
administrator require information about current sessions or current
users.
--
Regards,
Ketan
Wednesday, August 29, 2007
Linux : setting up rdist
server. rdist stands for remote distribution. Many useful options are
available with the command.
See `man rdist` for more information about the command.
This is how I set up rdists :-)
My crontab entry
10 * * * * rdist -f $HOME/bin/rdist_file > /dev/null
###rdist_file contains
## these are comments
/path/of/source/file -> target_server1 install
-onochkowner,nochkgroup,nochkmode /path/to/the/target/file;
### file rdist ed to target_server2
/path/of/source/file -> target_server2 install
-onochkowner,nochkgroup,nochkmode /path/to/the/target/file;
Linux : splitting a log file
% split -l 5000 file
This creates files like xaa, xab etc.
Thursday, August 23, 2007
Thursday, August 09, 2007
Leaving my job
decided to start working as a Consultant in the field of Linux,
Apache, MySQL, Perl/PHP. After joining Fluent, I developed liking for
the Linux platform and the open source technologies.
During my tenure with Fluent, I wrote many complex perl scripts and
modules. Now, I think Open Source is the field where I can help the
community and grow individually as well.
Monday, May 14, 2007
html source and bandwidth usage
If a website gets some 400 pageviews per day, you send 400x30 (sligtly more than 1 Kb) extra bytes per month.
This means 1 character may mean 1 Kb of bandwidth usage per month for a website of low traffic. More the traffic more the size associated per character.
Therefore, to save the bandwidth and to improve loading speed of your pages, optimize your templates and html !
Wednesday, February 28, 2007
mod_perl : DBI.so/GD.so can't be loaded
If you are using Apache2, you are lucky in the sense that you won't have to compile apache with mod_perl. Just re-build perl and install it and then build mod_perl and install.
Monday, January 22, 2007
PHP : Handling multiple select menu
Note the square brackets and the multiple="multiple" part in the form.
HTML form
---------
<form action="some_action_file.php" method="post">
<select name="select_name[]" multiple="multiple">
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
<option value="d">d</option>
</select>
<input type="submit" value="Submit" />
</form>
PHP part
----------
<?php ## some_action_file.php foreach ($_POST['select_name'] as $select_name){ echo "$select_name<br />"; ## prints all the selected values; one per line } ?>
Monday, January 15, 2007
Perl : Removing last newline in while
while(<>){
chomp if eof; ### eof returns 1 if next read on filehandle returns end of file
print;
}
Friday, January 05, 2007
Perl : Locating a perl module file
find `perl -e '$,="\n";print @INC'` -name Template.pm
Note
The perl command is in back-ticks. This is an example of command execution within a command.
Thursday, January 04, 2007
Networking : Switches versus Hubs
I can think of following differences between a hub and a switch.
1. Hub requires no knowledge of how it works. It's easy to install. The same is not true with switches. Even if the manual s
ays "plug and play switch", it's better to know how switches work.
2. You may have to configure your NICs (network cards) so that the switch communicates. To configure network cards, you need
to learn what to configure.
3. Switches offer you a learning opportunity :-). In the process of making your network work for you, you'll learn people me
an by words like duplex auto-negotiation and speed.
4. If you are required to troubleshoot, you learn still more. In that case, you'll learn commands like ethtool, ifconfig, tr
aceroute, ifup, ifdown etc.
5. Conlusion is, Switches are better than hubs not only because of the reasons you read on the net, but they also teach you
networking.
Monday, December 11, 2006
Linux : renaming files with rename in a loop
for file in `find . -type f -name "*.TXT"`; do rename .TXT .txt $file; done
The above works in bash. For use in other shells, you'll have to change the looping sytax.
Thursday, November 23, 2006
Perltidy
For more information and download of Perltidy, visit
http://perltidy.sourceforge.net/
Perltidy is coool !
Monday, November 20, 2006
Linux : Killing processes
Here's the time-saver
ps -ef | grep httpd | awk '//{print $2}' | xargs kill
You can use the same logic for other processes. You need to replace httpd with ..... you know. As you can see, awk separates just the process ids and it becomes easier for us to kill the processes !
Sunday, November 19, 2006
Perl : Is this module Installed ?
On the command-line, issue this command
perl -e 'use X::Y'
X::Y is the module
With -e, you can executes the perl code in quotes on command line.
If the module is found, there won't be any errors (no output).
Friday, November 17, 2006
Perl : Generating password with a subroutine
sub generatePassword
{
my $passwd_size = shift;
my @alphanum = ('a'..'z', 'A'..'Z', 0..9,'!','#','$','%','&','*','@','`');
my $password = join '', map $alphanum[rand @alphanum], 0..$passwd_size;
return $password;
}
Usage
&generatePassword(10); ### returns password of 10 chars
Tuesday, November 14, 2006
Perl : Installing CPAN modules
1 Become root
2. Run
perl -MCPAN -e shell
First time you run this command, you'll be asked some questions regarding where to download/extract files etc. Just select the defaults.
3. This opens the cpan prompt. Now, run
install Module::Name
That's all you have to do. Isn't this really simple ?
Saturday, November 11, 2006
osix.net : A good website for programmers
A great site for geeks !
My profile there
http://www.osix.net/modules/viewprofile/?name=ketan404