Virtual box NAT+ Host-only (static )

  1. Set the network adapter for Host-only NetworkVirtualbox-File-preference-Network
  2. Set the guest OS networkVirtualbox-GuestOS-Network
  3. Start the guest OS
  4. Edit /etc/network/interfaces as below.
    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).
    
    source /etc/network/interfaces.d/*
    
    # The loopback network interface
    auto lo
    iface lo inet loopback
    
    # The primary network interface
    auto enp0s3
    iface enp0s3 inet dhcp
    
    #static ip experiment
    auto enp0s8
    iface enp0s8 inet static
    address 192.168.27.101
    netmask 255.255.255.0
    
  5. Either restart the VM or run the below command to restart the network
  6. sudo service networking restart
  7. Now you should be able to perform ping or ssh from your host machine to this guest OS
  8. If SSH is not enabled in the server follow the below link to configure open ssh.  http://ubuntuhandbook.org/index.php/2016/04/enable-ssh-ubuntu-16-04-lts/
Advertisements

Clone or Install the Perl modules from one machine to another

Developers or system integrators install lot of Perl modules on their machines when they wanted to try with some applications or modules or APIs. But when they wanted to use the same installed modules to some other servers/machines they need to do the same exercise again on the other machines.

CPAN shell has an inbuilt feature to deal with this scenario.


perl -MCPAN -e "autobundle"

This will create a bundle file which will contain all installed modules available in the path of @INC

<user_home_directory>/.cpan/Bundle/Snapshot_2015_04_16_01.pm

Now copy that bundle file to any machine and run the below command to get all those modules available in the old machine.


perl -MCPAN -e 'install Bundle::Snapshot_2015_04_16_01'

Quick reference -CVS

All information in this is based on the documentation (http://cvsgui.sourceforge.net/howto/cvsdoc/cvs_5.html#SEC61) and my practical experience

Create a branch and add a file into a branch
Step1: Checkout the path of code for which you want 2 make a branch into a new sandbox
Step2: Branch created with all files present in the directory.
       $cvs tag -b BRANCH_NAME_YOU_LIKE_TO_GIVE
Step3: To verify the creation either checkout the branch or update the path with the branch details
       $cvs co -d DIR_NAME -r BRANCH_NAME_YOU_LIKE_TO_GIVE CVS_PATH_OF_THE_MODULE_YOU_WANT_TO_CHECK_OUT
or go into the path where your code resides and run the below comand to update all files in that path with this branch
       $cvs upd -r BRANCH_NAME_YOU_LIKE_TO_GIVE

Step3: Adding single file to the newly created branch
       $cvs tag -b BRANCH_NAME_YOU_LIKE_TO_GIVE your_perl_file.pl

Merge Changes from Branch to Trunk

  Consider this revision tree:

    +—–+    +—–+    +—–+    +—–+
    ! 1.1 !—-! 1.2 !—-! 1.3 !—-! 1.4 !      <- The main trunk
    +—–+    +—–+    +—–+    +—–+
                    !
                    !
                    !   +———+    +———+
        Branch R1fix -> +—! 1.2.2.1 !—-! 1.2.2.2 !
                        +———+    +———+
The branch 1.2.2 has been given the tag (symbolic name) `R1fix’. The following example assumes that the module `mod’ contains only one file, `m.c’.

  $cvs checkout mod               # Retrieve the latest revision, 1.4

  $cvs update -j R1fix m.c        # Merge all changes made on the branch,
                                 # i.e. the changes between revision 1.2
                                 # and 1.2.2.2, into your working copy
                                 # of the file.

  $cvs commit -m “Included R1fix” # Create revision 1.5.
A conflict can result from a merge operation. If that happens, you should resolve it before committing the new revision.
            OR

The checkout command also supports the `-j branch’ flag. The same effect as above could be achieved with this:
    $cvs checkout -j R1fix mod
    $cvs commit -m “Included R1fix”

Creating Tags
$cvs co -d dirname Module
$cvs tag Tagname
This will hep you to create a snapshot of the current updated code in CVS. This is very helful we want to restore the code to this point at some time even if we have done enough coding on the HEAD.

Command to Update the code base with HEAD and BRANCH code.
# Update the sandbox with trunk
$cvs upd -A
# Update the sandbox with a branch
$cvs upd -r BRANCH_NAME

Quick Reference- Perl one liners

#search for a pattern in a file just like Linux grep command
$perl -ne ‘print if /findword/;’

#search and replace a pattern in a file and print the modified contents on the screen
$perl -pe ‘s/findword/replaceword/g;’

#search and replace a pattern in a file. Original files are backed up in .bak extension. This is one of the most powerful command if you want to do operations on large set of files in a directory.
$perl -pi.bak -e ‘s/findword/replaceword/’

#see the encode and decode characters of URLs
$perl -MURI::Escape -le ‘$var=qq(userid,;); print uri_escape($var);’
$perl -MURI::Escape -le ‘$var=qq(userid%2C%3B); print uri_unescape($var);’

Screen Tips for Linux users

Screen is Linux window manager program which helps users to a have a window session open with multiple shells/tabs. Screen will start a process that continuously runs on the server. User can open multiple tabs/shell within the main Session to switch between different tabs/shell.

Screen is useful when:
•    You want to run a program which can take long time to complete.
•    You have an internet connection that often drops.
•    You want to work with multiple servers and do not want to have different putty shells opened.
•    You want to save the work environment on each servers and came back on each day and start the screen to get the session connected to the servers where you left off.

Example: I want to start a process and check it status at a later time.
You can use nohup or start the process in background. But if the network is disconnected, you may not get the same shell which I started the process. Here come screen for you. Start the process from after starting the screen session, detach the screen and close your putty connection. You can check the status of the started process by re-attaching the screen session at a later time by connecting the putty. Once the process is started with the screen session, there is no need to bother about the internet connection to the server unlike when you run the process from a normal shell prompt.

Few are some of the useful commands using screen:
#start screen session with name session_name and tab titles with name title_name
$screen -S session_name -t title_name
#to detach the session and resume
$screen -r -D session_name
#to resume a detached session
$screen -r session_name
#to kill a detached or not responding screen session with name screen_session
$screen -r screen_session -X quit

Some useful key bindings:
Ctrl+a+d  => Detach the screen session from the current shell.
Ctrl+a+c => Create a new tab/window within the session
Ctrl+a+n => switch the screen in forward mode
Ctrl+a+p => switch the screen in backward mode
Ctrl+a then shift+a => To change the title of the tab/window

Below is the .screenrc file which I use in my day to day work.
cat ~/.screenrc
#scrollback control lines
termcapinfo xterm|xterms|xs|rxvt ti@:te@
# Kill the annoying flickering on key presses
vbell off
#screen title captions format displayed at the bottom
caption always '%H %c | %-w%{=}%n-%t%{-}%+w'

________________________________________
More detailed information on Screen can be found at http://www.gnu.org/software/screen/manual/screen.html