Ubuntu « Intelligrape Groovy & Grails Blogs

Posts Tagged ‘ Ubuntu ’

Install RhoSync on ubuntu 11.10 (with fix)

Posted by on September 18th, 2012

Recently, I was trying to install RhoMobile suite on my ubuntu11.10 machine. And faced some issues for installing ‘rhosync’ package. This blog tells how to fix these issues (as they worked for me).

 

I am assuming ruby and gem are already installed on your machine.
Note: if you are on older version of ruby please upgrade to 1.9.2

 

Rhodes was installed without any problem –

sudo gem install rhodes

Now, the problem arrived for installing RhoSync

salil@local:~$ sudo gem install rhosync
Building native extensions.  This could take a while...
ERROR:  Error installing rhosync:
    ERROR: Failed to build gem native extension.

/usr/bin/ruby1.9.1 extconf.rb
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- mkmf (LoadError)
    from <internal:lib/rubygems/custom_require>:29:in `require'
    from extconf.rb:1:in `<main>'

 

To fix the above error, run following command –

apt-get install ruby1.9.1-dev

Now retry installing rhosync.

sudo gem install rhosync

Now, you will see the ‘rhosync’ getting installed successfully.

 

Another common error -

ERROR:  Could not find a valid gem 'Rhosync' (>= 0) in any repository

To fix the above error, check the following points-
1. Check the name of the package you are trying to install. It should be ‘rhosync’ instead of ‘Rhosync’. It’s case-sensitive.
2. It’s possible that the source for your gem repository is empty. So, add one with the following command –

gem sources --add http://rubygems.org

 

Cheers!
Salil Kalia
Salil [at] IntelliGrape [dot] com
Twitter LinkedIn

Posted in Android, Linux

Sending email through command line with Mutt

Posted by on September 12th, 2012

In one of the shell scripts I was reading I saw a usage of mutt text-based command line email client. Mutt can be used to send out the emails from the production machines or any other servers where you do not have access to the browsers or UI based email clients. Sometimes it is essential to send out a particular log file to certain people for bug fixing while you are checking on the prod machine.

Here is how you can send out the emails from the Linux (at-least for most of the Debian based distributions such as Ubuntu)

  sudo apt-get install mutt

Now you can type in the following command:

 mutt -s <emailSubject> <recipientEmail> -c <ccRecipientEmail> -b <bccRecipientEmail> -a </path/to/the/attachmentFile> < </path/to/the/fileContainingTheMessage>

We can see an example here:

 mutt -s "Demo Subject Line" xyz@xyz.com -c abc@xyz.com -b blind-recipient@xyz.com -a /tmp/meetingDetails.xls < /tmp/emailBody.txt

As you can see, the -s flag is used to specify the subject line of the email and the optional flags -c and -b are used to specify the “cc” recipient and “bcc” recipient respectively. Also, -a flag is used to specify the location of the attachment file. There is one caveat regarding the -a flag i.e. -a option must be placed at the end of command line options. You can read the mutt documentation for more information on this.

This utility is a nice to know tool if you are a developer working in Linux and can use it in shell scripts when ever there is an apt use-case. You can read more about mutt and other cool things it can do by clicking here or by typing the ‘man mutt‘ command in your terminal.

Hope this helps !!

- Abhishek Tejpaul
abhishek@intelligrape.com

Posted in Linux, System

Auto Completion for Grails Scripts with Dynamic Version Determination

Posted by on August 16th, 2012

We are constantly striving to be more productive by minimizing key-strokes for a lot of commonly used shell commands. Alias is one way of achieving it, but it isn’t always the answer. Bash auto completion is one feature that I use a lot.

To avoid the hassles of working with multiple grails projects, I use this script and for auto completion, I use this wonderful auto completion script by Ted Naleid. However, there were a few more scripts/arguments which we thought would be a great addition to the auto-completion set. Scripts provided by plugins was one such set and this had to come from the appropriate directory under .grails/$GRAILS_VERSION/projects/$PROJ_HOME/plugins/*/scripts. Another set of options which I thought appropriate were the system properties that we provide.

So, I came up with the custom auto completion script given below


_grailsscripts() {

    if [ -z "$PROJ_DIR" ]
    then
       if [ -e "application.properties" ]
       then
          export GRAILS_VERSION=`grep app.grails.version application.properties | sed -E 's/.*=(.*)/\1/'`
          export GRAILS_HOME="/opt/grails-$GRAILS_VERSION"
          PWD=`pwd`
          export PROJ_DIR=`basename $PWD`
       fi
    fi
    SCRIPT_DIRS="$GRAILS_HOME/scripts ./scripts ~/.grails/scripts"
    if [ "$PROJ_DIR" ]
       then for PLUGIN_DIR in $(ls -d ~/.grails/$GRAILS_VERSION/projects/$PROJ_DIR/plugins/*/scripts 2&gt; /dev/null); do
       SCRIPT_DIRS="$SCRIPT_DIRS $PLUGIN_DIR"
       done
    fi
    if [ -d plugins ]
       then for PLUGIN_DIR in $(ls -d plugins/*/scripts 2&gt; /dev/null); do
       SCRIPT_DIRS="$SCRIPT_DIRS $PLUGIN_DIR"
       done
    fi

    for D in $SCRIPT_DIRS; do
       if [ -d $D ]
         then ls -1 $D/*.groovy 2&gt; /dev/null | sed -E 's/(.*)\/(.*)\.groovy/\2/' | sed -E 's/([A-Z])/-\1/g' | sed -E 's/^-//' | tr   "[:upper:]" "[:lower:]"
       fi
    done | sort | uniq | grep -vE "^_"
}

grailsOpts="-Dserver.port= -Dgrails.env= test dev prod"

_grails() {
 COMPREPLY=( $(compgen -W "$(_grailsscripts) $grailsOpts" -- ${COMP_WORDS[COMP_CWORD]}) )
}

complete -F _grails grails
complete -F _grails grails-debug

Now, all you need is to add this script under /etc/bash_completion.d/


Hope this helps you save a few keystrokes.

Posted in Grails, Linux

How to Set-up SSL certificates on your Linux server

Posted by on June 1st, 2012

In one of my project, I have to set-up SSL certificates for my website to make it secure, so that it could also be access via https protocol. SSL is a way to secure internet communication from your browser to a secure website. The websites using SSL will have https:// to their name.

Following are the steps to set-up SSL certificate on your server:
1. Issue Command to Generate Key: openssl genrsa -des3 -out www.MY_DOMAIN_NAME.com.key 2048.
2. Issue Command to Generate CSR(Certificate Signing Request):
openssl req -new -key www.MY_DOMAIN_NAME.com.key -out www.MY_DOMAIN_NAME.com.csr.

This command will prompt for the following X.509 attributes of the certificate:
– Country Name: Use the two-letter code without punctuation for country, for example: US or CA.
– State or Province: Spell out the state completely; do not abbreviate the state or province name, for example: California
– Locality or City: The Locality field is the city or town name, for example: Berkeley. Do not abbreviate. For example: Saint Louis, not St. Louis
– Company: If the company or department has an &, @, or any other symbol using the shift key in its name,the symbol must be spelled out or omitted, in order to enroll. Example: XY & Z Corporation would be XYZ Corporation or XY and Z Corporation.
– Common Name: The Common Name is the Host + Domain Name. It looks like “www.company.com” or “company.com”. etc.
You can skip other attributes by pressing return (or enter)

3. You can verify your CSR (Optional) Here
4. Now, At verilog site or any other site apply for test certificates and fill up the details over there, paste your www.MY_DOMAIN_NAME.com.csr file content on the request form and submit it.
5. After few minutes, You will receive an email which contains the certificate attached in its body, copy that certificate and save it as www.MY_DOMAIN_NAME.com.crt on your server. (For email,check your spam also ;) )
6. Enable MOD-SSL by Issuing Commands: a2enmod ssl
7. Now you need to update the apache config file. Open you sites apache-config file located at /etc/apache2/sites-available/YOUR_SITE_NAME. This is an XML File . Modify “VirtualHost *.80” to “VirtualHost *.443” (443 Port is used for SSL) and paste the following code inside the “VirtualHost *:443” tag.

SSLEngine on
SSLCertificateFile COMPLETE_PATH_TO_CRT_FILE (like /home/user/ssl/www.MY_DOMAIN_NAME.com.crt)
SSLCertificateKeyFile COMPLETE_PATH_TO_KEY_FILE (like /home/user/ssl/www.MY_DOMAIN_NAME.com.key)

– Note: For using both http and https protocol, copy and paste “VirtualHost *.80” tag, modify copied “VirtualHost *.80” to “VirtualHost *.443” (443 Port is used for SSL) and paste the above code inside your “VirtualHost *.443” tag.

7. You can verify your apache config, using the command: apache2ctl configtest
8. Restart apache by issuing command: /etc/init.d/apache2 restart OR apache2ctl restart

Hope it helps.

Regards,
Gautam Malhotra
gautam@intelligrape.com

Posted in Linux, System

Set-up SSL Communication between two Linux servers Using Keytool Command

Posted by on May 31st, 2012

In one of my project, My front end application runs on one server and back end application runs on another. Both application have to communicate with each other through SSL(Secure Sockets Layer). SSL is a way to secure internet communication from your browser to a secure website. The websites using SSL will have https:// to their name.

In comes the Java keytool command, which is a key and certificate management utility. Keytool is a java security tool, which is used to create and manage public keys,private keys,and security certificate. It manages a keystore (database) of cryptographic keys, X.509 certificate chains, and trusted certificates.

Using the Java keytool command you can add the certicate into your keystore as trusted certificate.

Following are the steps to perform https communication between two application on different servers:
1. Copy server1-site.crt file to Server 2.
2. Now, Import this root or intermediate CA certificate to an existing Java keystore, using the command:
    Default keystore password is changeit

keytool -import -trustcacerts -keystore cacerts -storepass YOUR_KEYSTORE_PASSWORD -noprompt -alias webAppCertificate -file www.web-app.mydomain.com.crt

3. Restart apache by issuing command: /etc/init.d/apache2 restart OR apache2ctl restart
4. Repeat, Steps 1 to 3 on server1 with server2-site.crt file.

Using the keytool command you can add , delete ,list certificate from your keystore.

Refrence: http://www.sslshopper.com/article-most-common-java-keytool-keystore-commands.html

Hope it Helps!

Regards,
Gautam Malhotra
gautam@intelligrape.com

Posted in Linux, System

Forgot Root Password in Linux, How to Reset Root Password through GRUB?

Posted by on March 28th, 2012

Hi,
 
It is a major problem when we forgot our root password in linux. But don’t know how to recover it. First thought that came to mind reinstall machine. But I found a way that might help you without reinstall and save your hours. It is a interesting trick in linux to get back our root password in few minutes. I used it on ubuntu 11.10 it work fine for me. Some people might know about this method, but I thought i share with you all for those who don’t know.
 
Caution : But please don’t play with this for fun, only use it when in need.
 
Here are the steps to get back your password :
1. Reboot your system.
2. When Grub Loads, Either move arrow to stop clock/timer.
3. Select Ubuntu Kernel, and then Press ‘e’ key to open it in Edit Mode.
 

 
4. In edit mode, screen will look like this in Ubuntu…
 

 
If you see the 2nd line from bottom, that says info about kernel add ’1′ in end of command as given below,
linux /boot/vmlinuz-2.6.31.9 root=UUID=904bf39-9234 ro quiet splash 1
 
5. Then Press Ctrl + b to boot kernel in single user mode.
6. By using passwd command reset your root password,
root# passwd
New UNIX Password:
Retype UNIX Password:
passwd updated successfully
 
7. Now reboot the machine, machine will reboot with your new password.
 
I hope it helps. ;)
 
Thanks,
Tarun Pareek
tarun@intelligrape.com
http://in.linkedin.com/in/tarunpareek
More Blogs by Me

Posted in Linux, System

Speeding up Ubuntu

Posted by on December 6th, 2011

Of-late my laptop has been highly responsive …. as responsive as a sloth can be… :P
I mean you wouldn’t be expecting an Intel i5 Processor with 4GB Ram and 500GB hard disk making you go for a coffee break every time you had to build or compile your code.
I am sure many of you must have experienced some form of lag with your Ubuntu (I am using 11.10… But I did experience some form of lag with 10x series also).

So in this blog post I’ll be discussing some ways that you can follow to speed up your Ubuntu

1). Disable StartUp Apps the Smarter Way

Now when I started up StartUp Applications on a my Ubuntu 11.10 installation, all you can see are a mere 5-6 apps. Mine Actually had a whole lot more that were run at start up but are simply not shown like Yakuake, Gwibber, Desktop Sharing Sevrer, Bluetooth Manager etc. Ubuntu 11.04 was somewhat better where you could see most apps but still not all that would be let loose at startup. Using the following commands, I was able to enable all apps running at startup to be shown here.

cd /etc/xdg/autostart
sudo sed --in-place 's/NoDisplay=true/NoDisplay=false/g' *.desktop

Once that was done, restarting Startup Applications now showed all the apps that were running at startup. Just read the description once and decide whether you want to keep it at startup or not.

Startup Applications shown Initially

Startup Applications Now Showing Full List

Startup Applications Now Showing Full List

rcconf is another tool that can be used but I found this method much more comprehensive and user friendly.

2). Swappiness is inversely proportional to Happiness :D

Swappiness is a property for the Linux Kernel that decides on how often to use the swap space. Most of the laptops today are equipped with 3-4 GB of Ram. So the principle of having double the swap space w.r.t to your memory size seems a bit outdated to me. Even though there was plenty of Ram available, my OS insisted on using the swap space, which in turn decreased responsiveness.
So I then moved on to change the swappiness value(Range:0-100, Default: 60)
Since I had a decent amount of RAM that could handle almost anything that was thrown at it, I decreased the swappiness quotient to 20.
To check the current swappiness value just type the following..

 cat /proc/sys/vm/swappiness 

Next to adjust the value swappiness value open

 sudo vim /etc/sysctl.conf 

Search for vm.swappiness and to change it to a desired value.If it is not present just add it to the end of the file. 10 is the figure that is mentioned on many forums, but I decided to play a bit safe and kept it a 20. Simply restart your system for the changes to take effect.

3). Reload Swap contents to Memory

Although I felt that decreasing the swappiness quotient did work for my computer, it is still possible that your computer swaps. This can hurt the multitasking performance of your system.
I found this script that you can use to to get the swap manually back into RAM.

err="not enough RAM to write swap back, nothing done"
mem=`free|grep Mem:|awk '{print $4}'`
swap=`free|grep Swap:|awk '{print $3}'`
test $mem -lt $swap && echo -e $err && exit 1
swapoff -a && swapon -a &&
exit 0

And place it at somwehere like

  /usr/local/sbin/swap2ram.sh 

Once you execute the script, it will transfer all your swap contents back to Memory, and free up your swap space. What it essentially does is turn off  swap space forcing everything back into RAM and turning it back on.

There are many more things that you can do to tweak up the speed of your computer, though I felt these 3 steps helped me a lot.
Hope this Helps :D

Manoj Mohan
manoj(at)intelligrape(dot)com
Tags: , ,
Posted in Linux, System

Creating a Perfect System in few minutes.

Posted by on October 22nd, 2011

There might come up a case where you need to install same kind of OS and other Softwares( which are required for daily use) on multiple systems. One of the ways to do it is follow the same procedure on each of the machines, which is obviously a pain. Here’s a easy way to do it by using Clonezilla.

Now with clonezilla you will have to setup one system only, this this would obviously take time. But once the first system is done, you can just setup rest on other machines in few minutes.

Here are the steps, that I used to follow to create system with both Windows 7 and Ubuntu in under 10 minutes. With all softwares installed which included Counter strike on windows, Couple of IDE’s on Ubuntu and Git , mySql , Java and more on Ubuntu.

  1. Setup a perfect system. Install OS and other software that are required. Once the system is ready we need to download few softwares.
    1. 7zip ( p7zip-full_9.04~dfsg.1-1_i386.deb).
    2. Tuxboot (Tuxboot-linux-8 ).
    3. Clonezilla (clonezilla-live-1.2.6-40-i686.iso).All three of these are freely available.
    4. And we would also need a USB drive preferably with space more than 16GB , as windows 7 installation takes 15 GB approx and Ubuntu 11.10 will take around 6GB and little extra for other softwares. Clonezilla uses very effective compression technique will reduce size to approx half. So 16GB USB drive would work just fine.
  2. Install CloneZilla on USB drive.
  3. Once Clonezilla is installed , its time to make image of Perfect System.
  4. After image is done, we are ready to clone out perfect system, to other machines.
  5. Making Clone of Existing image, Process to make clone are pretty much same as process described in step-3. Except Step-11 of “making image” . Just select restore disk, this will create clone of image on disk. And ALL EXISTING DATA FROM DISK WILL BE ERASED. Following  are the links of images depicting step 5.  Image 1,Image 2,Image 3,Image 4,Image 5,Image 6,Image 7,Image 8,Image 9. There images are taken from a camera, hence please don’t mind  their quality.
  6. This is it , your next system is ready within few minutes. Now this process can be repeated again and again, to create clone of existing systems.

_________________________________
Hitesh Bhatia
Mail,LinkedIn,Facebook,Twitter
_________________________________
Posted in Grails

Installing CloneZilla on USB drive using Ubuntu.

Posted by on October 22nd, 2011

Clonezilla is a software that allows you to do bare metal backup and recovery.

To install Clonezilla we would need following Softwares, all of which are available freely.

  1. 7zip ( p7zip-full_9.04~dfsg.1-1_i386.deb)
  2. Tuxboot (tuxboot-linux-8 )
  3. Clonezilla (clonezilla-live-1.2.6-40-i686.iso)

Here are the steps to install CloneZilla

  1. Install 7zip required to install Tuxboot
    1. sudo dpkg -i p7zip-full_9.04~dfsg.1-1_i386.deb
    2. It would show something like
    3. (Reading database … 168886 files and directories currently installed.)
    4. Preparing to replace p7zip-full 9.04~dfsg.1-1 (using p7zip-full_9.04~dfsg.1-1_i386.deb) …
    5. Unpacking replacement p7zip-full …
    6. Setting up p7zip-full (9.04~dfsg.1-1) …
    7. Processing triggers for man-db …
    8. And Step 1 is done. 7Zip is Installed.

2. Run tuxboot

    1. By default tuxboot is not executable , change it permission to make it.
    2. chmod +x tuxboot-linux-8
    3. Run tuxboot with sudo permission
    4. sudo ./tuxboot-linux-8
    5. Set the values as shown in image

    Step 5 - Installing Clonezilla

    5.1. Select Diskimage – then in adjacent dropdown select iso
    5.2. And then select the clonezilla image ( the one you downloaded)
    5.3. Type – usb drive
    5.4. Press “OK” . And let it complete. It will ask to reboot afterwards , but you can also reboot later

3. And your clonezilla usb is ready now. You may now use it to clone systems.

_________________________________
Hitesh Bhatia
Mail,LinkedIn,Facebook,Twitter
_________________________________
Posted in Linux, System

Organizing “.bashrc”

Posted by on August 17th, 2011

I have been working on Linux for almost 3 years now and have grown to love it a lot.

As with every linux user, the .bashrc file becomes cumbersome and difficult to maintain over a period of time, since there are a lot of project specific aliases, paths, etc

So after working on a couple of projects, I started maintaining separate files for my environment settings. So I just had to create a separate project setting file:

~/.myProjectSettings
alias myAlias1='cd /to/project/dir'
alias projectqa='ssh to@qa'
alias projectDb='mysql -u<username> -p<password> <project_db_name>'

So, everytime I had to add more project specific settings or separate my settings, I had to create a new settings file and then source it in my .bashrc by adding this line

. ~/.myProjectSettings

As you can guess, after doing this a couple of times, even this was becoming very tedious.

So, I tried to follow the golden rule of convention over configuration.

In my .bashrc, I added the following function :

function sourceAllMySettings(){
	FOLDER_TO_BE_SOURCED=~/.mySettings/
	for i in `find $FOLDER_TO_BE_SOURCED -type f`; 
	do 
		. $i
	done;
}
##don't forget to execute the function
sourceAllMySettings

and placed all my setting files into the folder :

~/.mySettings/

So, now if I have to add more settings to my .bashrc, I just create a new executable file in this folder and it gets automatically sourced.

Goodbye messy .bashrc, welcome organized (segregated) settings :)

Regards
~~Himanshu Seth~~

http://www.IntelliGrape.com

Tags: ,
Posted in Linux