Tuesday, July 26, 2011

Capistrano Using User Input

Capistrano does not accept ruby methods. Suppose I need to get user input I can't use gets.strip and it would spew Method not found error.

You can use the following method to get the user input in capistrano deploy scripts.
==============
puts "This is a critical code do you want to proceed (y/n)"
value = STDIN.gets[0..0] rescue nil
exit unless value == 'y' or value == 'Y'
===============

Capistrano is full and fast automation solution. Don't include too much of user interaction in that unless necessary.

Tuesday, July 12, 2011

Bash Execute a Remote Command as Sudo

Just difficult for me to remember this thing. This is a way to execute remote command which can executed only using sudo privileges.
===============
ssh -t testuser@testserver "/usr/bin/sudo sh -c w"
===============

Thursday, July 7, 2011

Migrate Thunderbird email from Mac to Ubuntu

This is a simple step to migrate thunderbird mails from Mac OSX to Ubuntu.


Create the following directories in Ubuntu Desktop

cd /home/rayber
mkdir .thunderbird

Mount the mac HD

mount -t hfsplus /dev/sda2 /media/mac
Copy the data from mac homedir

cp -rpf /media/mac/Users/home/rayber/Library/Thunderbird/* .thunderbird/


You are now good to go. Start thunderbird and you should be able to start from the place where you stopped in Mac.

Tuesday, July 5, 2011

SSH with Empty Password and no ssh keys

This is a guide to zero security in linux. It is applicable only in places where security is not a threat and there is no threat from external networks.

The following options would allow a system running ssh to have a user with empty password so that you can use this user to login without any password or ssh keys.


I am adding a test user for this purpose.

useradd noneknowme
passwd -d noneknowme

Configure ssh server to allow empty passwords.

Edit the following line in /etc/ssh/sshd_config
================
PermitEmptyPasswords yes
================

Restart sshd using /etc/init.d/sshd restart

Now you should be able to access the host with ssh with username noneknowme without any issues.
===============
ssh -l noneknowme test
[noneknowme@test ~]$
================

Don't try this . I am using this as a reference. Thanks to linuxquestions.org

Friday, July 1, 2011

script to check swap usage by process ( approximate )

The following command returns the total swap usage.

swapon -s

The following script would obtain the total MB of swap used obtained from proc filesystem and sum it up.

for pid in `ps -ef|grep -i java| grep -v grep|awk '{print $2}'`; do echo -n "Pid: $pid "; cat /proc/$pid/smaps |grep -i swap| awk '{SUM += $2} END {print "SUM: " SUM " kB (" SUM/1024 " MB)"}'; done

Thanks to linuxquestions.org

Monday, May 30, 2011

Zero Padding in Bash

I was wondering what is the best way to do "Zero Padding" in Bash. Suppose you need to iterate through a for loop and you need 01, 02, 03 sequence instead of 1, 2,3 then that is Zero padding.

Some of the methods I could get from the internet.

1. Using printf

for ((i=2;i<16;i++)); do printf "%02d" $i; done

2. Using seq

There were couple of solutions when you use seq

* seq -f '%02g' 1 15

* seq -w 1 15


Enjoy being fast using bash..

Wednesday, December 8, 2010

Backup mails in Thunderbird from Outlook

It has been a hard time working with Outlook and I was worried that it could crash at any time. I thought of backing up all the mails to thunderbird in another linux box. Reading the documentation I couldn't figure out any method using which we can import the .pst files to the thunderbird client.

Here is what I did to do the migration. Initially I took the backup from the outlook

Outlook -> File -> Import or Export -> Export to a file -> Personal Folder File (.pst )

Now it might take some time to take a complete backup. At the end we will get a big backup.pst file.


Transfer the file over to the Linux Desktop.

Since there is no way to import the .pst file directly to thunderbird. We might have to convert to mbox format to get this done. There are many tools to do that. In my case I used readpst.

1. Install Readpst

Readpst is with the package libpst.

yum -y install libpst

2. Convert the .pst file to mbox based format.

mkdir mail

readpst -o mail backup.pst


Now that we have mbox format of all the folders.

3. Install MboxImport utility in thunderbird.

Download the xpi from http://nic-nac-project.de/~kaosmos/ImportExportTools-2.4.1.xpi

Thunderbird-> Tools -> Addons-> extensions -> Install
Select the xpi file that you downloaded earlier and install it. Restart tomcat for the new extensions to take effect.

4. Import the Mbox mails to thunderbird.

Now that we have the mbox based mails in mails directory we can import the mails and account to thunderbird.

Thunderbird -> Tools -> ImportExportTools -> Import Mbox File -> Import entire directory (including sub directory)

Now you can select the "mails" directory in which we saved the mbox format files.


It might take some time for the import to happen. Now that you have a backup..Don't worry about old mails..