Category Archives: Unix/Server Stuff

All Unix and server related stuff.

Handling FTP usernames with @ in them

During my recent FTP adventures, I also found that some shared hosting sites give you an FTP username with the ‘@’ symbol in them. It is fine as long as you are going to use a GUI client to connect to FTP. But if you try using the commandline or Finder in Mac, you will have issues since the ‘@’ symbol is also used to separate the username from the host.

After some research I found that the ‘@’ symbol in the username can be replaced with ‘+’ while specifying it in the command line. I tested it with both wput and the Finder in Mac and it worked perfectly in both.

So remember, the next time you try to connect to FTP server from command line and you have a ‘@’ symbol in the username, then replace it with the ‘+’ symbol. Happy FTP’ing 😉

Posted in Unix/Server Stuff | Tagged , , | 4 Comments

Excluding .svn folders while transferring entire folder by FTP

Recently I had to transfer an entire folder, with lot of sub-folders to an FTP server. I know that there are lot of FTP GUI tools available that can do it, but I wanted to do it in command line so that I can script it.

I searched for the solution and came across an excellent tool called wput, which does exactly that very easily. It is very similar to wget, but instead of downloading the content, it allows you to upload it.

I installed it using apt-get and was trying to upload the entire directory. It was at this point I realized that I want to exclude all the .svn folders.

I again started searching for an answer. I even posted about it in stackoverflow, but couldn’t find a solution. I then went over the man page of wput and hidden inside was this gem, which allowed you decide on which files to include/exclude from the directory.

I thought of posting it here, so that it is useful for others and also I know where to find it when I need it next time.

So all you need is just one line. If you have not installed wput before, the install it using one of the following commands based on your operating system.

Posted in Unix/Server Stuff | Tagged , , | 3 Comments

Installing PHP 5.3.x in Ubuntu through apt-get or aptitude

Recently, I wanted to play around with some stuff which is available only in PHP 5.3.x (more about it later in a separate blog post) and so was looking for a way to install it on my Ubuntu server, where this blog is running.

After poking around a bit, I found that Karmic Ubuntu hasn’t upgraded to PHP 5.3.x yet and the only way to do is to compile from PHP source. Even though I am pretty comfortable doing it, I didn’t wanted to do it, because it is very difficult to upgrade at a later point in time.

I was continuing my research and then found that it is in fact possible to install PHP 5.3.x though apt-get or aptitude. I thought of documenting it here, so that it would be useful for others who want to do the same thing.

Adding dotdeb to the source list

First you should add dotdeb repository to your apt-get source list. Add the following two lines to your /etc/apt-get/sources.list file

sudo vim /etc./apt-get/sources.list

Adding dotdeb keys to keyring

Dotdeb packages are GPGsigned. Issue the following commands to add the keys to key-ring

Install PHP5 packages

Then issue the following command to retrieve the updated package list. I am using aptitude here; you can use apt-get as well.

sudo aptitude update

sudo aptitude upgrade

And then you can install PHP5 packages (and modules) using the normal install command.

sudo aptitude install php5 libapache2-mod-php5

Installing php5-dev package

The above method will install all php5-* packages, but php5-dev has some dependency issues with libtool packages. In order to solve that you have to manually install libtool v1.5.26. To do that use the following commands.

Now it’s time to enjoy the new features that are available in PHP5.3 🙂

Posted in Unix/Server Stuff, Web Programming | Tagged , | 17 Comments

Moved to Linode for hosting

Long time readers of my blog will know that I moved to Slicehost around 15 months back. I was pretty happy with their service, but now I have left them and have moved all my sites to Linode.  linode_logo_gray

Both Slicehost and Linode are good but when compared with Linode, Slicehost was slightly costlier. I realized it after reading the comparison done by David. I bought an account in Linode for testing and was quite happy with it. But I was lazy to move all my sites, since it involved some work.

The recent announcement by Linode to give 33% additional disk space wooed me enough and I gave in. 🙂

Now I am getting some additional features with Linode but for less cost. 😉

Posted in Unix/Server Stuff | Tagged , , | 4 Comments

Changing the default config editor in Ubuntu

If you are following the articles at Slicehost, then you may notice that PickledOnion uses nano as the default editor. I somehow like vi more than nano (not ready for a debate 😉 ) and was looking for a way to make vi the default config editor. After some googling, I found how to do it.

I am writing it down here so that all I have to remember is that I just need to search my blog if I need to do it again in future.

Okay the command you have to use is (I am assuming that you are not logged in as root, which is the recommended approach)

sudo update-alternatives --config editor

And then press the number corresponding to the editor which you want to use. Below is the screenshot of how it looked in my slice.

Changing default config editor in Ubuntu

Posted in Unix/Server Stuff | Tagged , , , , , | 2 Comments

Rotating Apache log files using Cronolog

I must confess that I am a stats freak. If you are a long time reader of my blog, then you would have known that by now yourself. 😉 This explains the reason why I want to preserve my Apache log files in spite of using a variety of stat services like Google Analytics, WordPress stats, statscounter, performancing metrics (before it was closed).

The default Apache configuration preserves the log files only for the last 10 days, but I wanted to permanently archive this files. After some searches in Google I came across an excellent program called Cronolog. Cronolog is a simple filter program which writes each log entry to a separate log file named after the filename format specified. You can use a variety of parameters like current date, time etc to define the filename template.

First we have to install cronolog, either by using aptitude or by downloading it from its download page. Then you have to change the log file name path in the virtual host file. (In Ubuntu Gusty, the virtual host files are situated in the path /etc/apache2/sites-enabled). I am using the following file format for this blog
# Custom log file locations
LogLevel warn
ErrorLog "|/usr/sbin/cronolog /path/to/logs/%Y/%m/"
CustomLog "|/usr/sbin/cronolog /path/to/logs/%Y/%m/" combined

which will store my log files in separate folders for each year and for each month, like the below hierarchy

You can use a variety of modifiers for the filename and I have documented some of them in the below table. You can get more information from its documentation.

Specifier Description
Time fields
%H hour (00..23)
%I hour (01..12)
%p the locale’s AM or PM indicator
%M minute (00..59)
%S second (00..61, which allows for leap seconds)
%X the locale’s time representation (e.g.: “15:12:47”)
%Z time zone (e.g. GMT), or nothing if the time zone cannot be determined
Date fields
%a the locale’s abbreviated weekday name (e.g.: Sun..Sat)
%A the locale’s full weekday name (e.g.: Sunday .. Saturday)
%b the locale’s abbreviated month name (e.g.: Jan .. Dec)
%B the locale’s full month name, (e.g.: January .. December)
%c the locale’s date and time (e.g.: "Sun Dec 15 14:12:47 GMT 1996")
%d day of month (01 .. 31)
%j day of year (001 .. 366)
%m month (01 .. 12)
%U week of the year with Sunday as first day of week (00..53, where week 1 is the week containing the first Sunday of the year)
%W week of the year with Monday as first day of week (00..53, where week 1 is the week containing the first Monday of the year)
%w day of week (0 .. 6, where 0 corresponds to Sunday)
%x locale’s date representation (e.g. today in Britain: “15/12/96”)
%y year without the century (00 .. 99)
%Y year with the century (1970 .. 2038)

Posted in Unix/Server Stuff | Tagged , , , , | 1 Comment

Accessing MySQL safely using port forwarding with PuTTY

During my days with dreamhost, in order to access MySQL from my local machine, I used to add my ip to the allowed host list. Even though security is compromised here, I really liked to use HeidiSQL for accessing MySQL database server instead of the built in MySQL console. But after my move to SliceHost, I found a little trick using which I can continue to use HeidiSQL from my local machine without adding my ip to the allowed host list.

This nice little trick is called port forwarding. Let me show you how I configured PuTTY so as to enable port forwarding.
First install MySQL and then configure SSH to use key based authentication and change the default port by following the articles at Slicehost. After installing MySQL and configuring SSH, download and install PuTTY from its download page. I recommend you to download the zip file containing all the files.

Then create a new session in PuTTY by entering the ip address and also the port. Then choose Connection -> SSH -> Tunnels. In the source port field enter a valid port number like 8600. In the destination field enter the value 3306 is the default port in which MySQL runs. The reason why I asked you to enter a different port in the source is that, in future if you run a MySQL server in your local machine for testing, it will clash with your port forwarding. Click the Add button and then start the session. Don’t forget to save the session.


Now open your favourite MySQL GUI client. Mine is HeidiSQL. In the connection settings, enter as the Hostname and enter the port which you specified in the source field in PuTTY (8600) as port. Also enter your username, password, default database name and the click connect.


Now the request which goes to port 8600 of your local machine is forwarded to port 3600 of your MySQL server by PuTTY and you can safely use a GUI client for MySQL without adding any ip to the allowed host list. Note that it will work only when PuTTY is having the session opened.

I hope this is of help to you and let me know how it is working for you. Happy PuTTYing 😉

Posted in Database Programming, Unix/Server Stuff | Tagged , , , , , | 7 Comments

Good Bye Dreamhost, Hello SliceHost

Finally, I am out of Dreamhost. My annual plan expired last November and I changed to monthly plan and was searching for a reason to change. The incident which happened last week became the final nail in the coffin and I am out of it now.

I have faced the bad neighbour problem and have had some outages because of it occasionally, but to be fair to Dreamhost, the problems I faced with them were not as bad as the ones which I had with my previous web host.

The other reason for me to change the host is that I have got fed up with shared hosting and wanted to dive into VPS. I thought of going with MediaTemple, but they were expensive and then tried GoDaddy Linux Virtual Dedicated plan. It really sucked! I was not getting the kind of control which I was expecting. More over the control panel itself took too much memory of 256 MB and the server was always at its knees.

It was then I read the review about SliceHost from Hosting Fu. I was doing some research and the moment I found the excellent article repository, I immediately went and registered. Right from the OS, everything is in your control and you can configure or install any software which you want. This is the type of control I was looking for. I selected Ubuntu Gusty as OS and have so far installed and configured Apache, MySQL, PHP, Subversion and Ruby on Rails. Finally I can get my hands dirty with Ruby on Rails, (which was actually one of my resolutions for 2007 🙂 )

I will keep you guys posted about my experience with SliceHost and also will post the interesting code snippets or configuration tricks which saves me some time. I am back to slicing my slice from slicehost 🙂

Posted in Unix/Server Stuff | Tagged , , , | 14 Comments

How best Linux compared with windows

I got this as an email forward from my friend the other day and I was not able to control my laugh for a couple of minutes. Hope even you enjoy it.

Long long ago, soo long ago, no one knows how long ago there was a classroom and the following is a dialogue between her and her students.

Ok so the stage is set and here it goes..

Question 1:

Teacher: What is 5 ^ 2? ( ^ stands for ‘raised to the power’ )

Windows said:

Windows Calculator

Linux: Huh! That’s too easy! Are you insulting me? Here’s the answer. Now ask more difficult ones.

Unix Shell

Question 2

Teacher: What is 123 ^ 123 ?

Windows said:

Windows Calculator

Teacher: Windows? What is this e+257 crap? Who asked you to express the result in an exponential form? I want the complete result, accurate up to the last unit’s place.

Windows: Sorry Madam! I don’t know how to calculate so accurately.

Teacher: Linux! Can you answer it the way I want?

Linux: Sure Ma’am! Have a look at my answer.

Unix Shell

Question 3

Teacher: Calculate 12345 ^ 12345 ?

Windows said:

Windows Calculator

Teacher: You are calling my question invalid? Ridiculous!! You should rather be saying, “Sorry! This is too much for me to calculate. I can’t do such huge computations.” Linux, I hope you won’t let me down.

Linux: Certainly not ma’am! You give me anything to do! I will always give you the answer and that too the way you want, correct up to the unit’s place. 🙂 Here’s my answer.

(The output was too big to capture in one screen shot! The output had to be redirected to a file. Then it was copied from there and pasted here. You can also get that file, if you want)

Ma’am the length of this result is seven hundred and forty lines (740 lines!!!) and I have calculated all the fifty thousand, five hundred ten digits (50510 digits!!!) accurately.

Teacher: Mind blowing Linux! Very well done! You’ll do great in your life. Windows, you might earn a lot of money in your life but you’ll never earn respect. You might find your way to every home and children might love to play games on you, but computer scientists and hackers would stay away from you. They would choose Linux instead. You’ll only manage to become an idiot-friendly operating system but never a useful operating system.

By the way, I tried to find out the original author but couldn’t find him. If you are the original author and if you have any license issue then do contact me.

Posted in Unix/Server Stuff | Tagged , , , | 16 Comments