Monday, November 19, 2012

Using the Perl chomp() function


Using the Perl chomp() function

Introduction

The chomp() function will remove (usually) any newline character from the end of a string. The reason we say usually is that it actually removes any character that matches the current value of $/ (the input record separator), and $/ defaults to a newline.
For more information on the $/ variable, try perldoc perlvar and see the entry for $/.

Example 1. Chomping a string

Most often you will use chomp() when reading data from a file or from a user. When reading user input from the standard input stream (STDIN) for instance, you get a newline character with each line of data. chomp() is really useful in this case because you do not need to write a regular expression and you do not need to worry about it removing needed characters.
When running the example below, using the enter key on a line by itself will exit the program.
  #!/usr/bin/perl
  use strict;
  use warnings;

  while (my $text = ) {
    chomp($text);
    print "You entered '$text'\n";
    last if ($text eq '');
  }
Example usage and output of this program is:
  a word
  You entered 'a word'
  some text
  You entered 'some text'

  You entered ''

Example 2. Chomping an array

If you chomp an array, it will remove a newline from the end of every element in the array:
  #!/usr/bin/perl
  use strict;
  use warnings;

  my @array = ("bob\n", "jill", "fred\n");

  print "Before chomp:\n";
  print "@array\n";

  chomp(@array);

  print "After chomp:\n";
  print "@array\n";
This program produces the following output:
  Before chomp:
  bob
   jill fred

  After chomp:
  bob jill fred
As you can see, the newlines have been removed from "bob" and "fred", but no characters have been removed from "jill".

Example 3. Chomping a hash

If you pass a hash into chomp(), it will remove newlines from every value (not key) of the hash:
  #!/usr/bin/perl
  use strict;
  use warnings;

  my %hash = (
    'first' => "one\n",
    'second' => "two\n",
    'third' => "three\n",
  );

  chomp(%hash);

  foreach my $k (keys %hash) {
    print "$k: $hash{$k} ";
  }

  print "\n";

  exit 0;
This program outputs:
  first: one second: two third: three

Wednesday, November 14, 2012

ReturnCode in unix


Shell Command Exit Status

The return value of a command is its exit status, or 128 + N if the command is terminated by signal N. Exit status is used to check the result (success/failure) of the execution of the command. If the exit status is zero, then the command is success. If the command is failed the exit status will be non-zero.

Exit Value Exit Status
0 (Zero) Success
Non-zero Failure
2 Incorrect usage
127 Command Not found
126 Not an executable
$? Shell Variable

The shell variable name $? is a special built-in variable which has the exit status of the last command executed.

After the shell function execution, $? returns the exit status of the last command executed in a function.
After the shell script execution, $? returns the exit status of the last command executed in the script.
Sample Shell Script that Explains Shell-Command Exit Status

The following exitstatus.sh shell-script shows examples of various shell-command exit status.

$ cat exitstatus.sh
#! /bin/bash

echo -e "Successful execution"
echo -e "====================="
echo "hello world"
# Exit status returns 0, because the above command is a success.
echo "Exit status" $?

echo -e "Incorrect usage"
echo -e "====================="
ls --option
# Incorrect usage, so exit status will be 2.
echo "Exit status" $?

echo -e "Command Not found"
echo -e "====================="
bashscript
# Exit status returns 127, because bashscript command not found
echo "Exit status" $?

echo -e "Command is not an executable"
echo -e "============================="
ls -l execution.sh
./execution.sh
# Exit status returns 126, because its not an executable.
echo "Exit status" $?
Now, execute the above exitstatus.sh to see the various exit statues given by the sample shell script.

$ bash exitstatus.sh
Successful execution
=====================
hello world
Exit status 0
Incorrect usage
=====================
ls: unrecognized option `--option'
Try `ls --help' for more information.
Exit status 2
Command Not found
=====================
exitstaus.sh: line 15: bashscript: command not found
Exit status 127
Command is not an executable
=============================
-rw-r--r-- 1 root root 659 Mar  9 13:36 execution.sh
exitstatus.sh: line 21: ./execution.sh: Permission denied
Exit status 126

Tuesday, October 30, 2012

Default Gateway and Subnet mask


Default Gateway - In a network using subnets, the router that forwards traffic to a destination outside of the subnet of the transmitting device.

Subnet mask - used to determine what subnet an IP address belongs to. An IP address has two components, the network address and the host address. For example, consider the IP address 150.215.017.009. Assuming this is part of a Class B network, the first two numbers (150.215) represent the Class B network address, and the second two numbers (017.009) identify a particular host on this network.

Preferred and Alternate DNS server - This is a server that translates domain names into IP addresses. Because domain names are alphabetic, they're easier to remember. The Internet however, is really based on IP addresses. Every time you use a domain name, therefore, a DNS service must translate the name into the corresponding IP address. For example, the domain name www.example.com might translate to 198.105.232.4.
The DNS system is, in fact, its own network. If one DNS server doesn't know how to translate a particular domain name, it asks another one, and so on, until the correct IP address is returned. So, it will check the "Preferred" DNS server first, if it can't translate the name, then it will hit the "Alternate" DNS server.


1. How do you determine what Class network it is?
2. How do you determine what the correct subnet mask of a network should be?
3. Can you explain the Default Gateway a bit more and how to determine what the Default Gateway should be under the TCP/IP Properties?
4. Explain a bit more on what a Subnet mask does
5. How to determine what the Preferred/Alternate DNS Server should be?
6. Are these all as simple as going and doing a ipconfig /all on the server to determine the addresses of these? And if so, how does the server get these addresses? Are they set by the router or are they set manually when you set up a server?

Answers :-
1. If it is a Local Area Network, the network administrator will determine the Class. This is based on how many hosts will be connecting and how many subnets are needed. There are 5 Classes: A, B, C, D, and E. Class D and E are used for multicasting, and are not used. Now you have a choice of A, B, or C. Class A's range is 1.0.0.1 to 126.0.0.0 This range allows up to 126 networks and 16777216 hosts.
A Class B Ip range is 128.0.0.0 to 191.254.0.0 which allows 16384 networks and 65536 hosts. A Class C range is 192.0.0.0 to 223.255.255.254 which allows 2097152 networks and 254 hosts on each of the networks.
Within a LAN, there are Private IP addresses that are set aside just for this purpose. They are 10.0.0.1 to 10.255.255.254 for a class A, 172.16.0.1 to 172.31.255.254 for class B and 192.168.0.1 to 192.168.255.254 for class C. Most Network Admins use 10.0.0.1 or 192.168.0.1.

Wednesday, August 29, 2012

OBIEE 11g (11.1.1.5.0) Installation on windows 7 64 bit, installation gets stuck at configuration stage

Issue:


OBIEE 11g (11.1.1.5.0) Installation  on windows 7 64 bit, installation gets stuck at configuration stage and log files show below lines

CSF Entries will not be parsed since the AdminServer is unreachable…..

Cause: This issue is because of the wrong entry in hosts file .



Solution:

Install the Loopback Adapter and update the hosts file file (C:\Windows\System32\drivers\etc) with the IP and your Computer Name

Eg: 127.0.0.1          ATMOHAMM.in.oracle.com     ATMOHAMM

Pre-installation checks for all platforms should include nslookups to confirm network and DNS settings. For example, the following command should return without error and the IP address and host should match those listed in the etc/hosts file:




nslookup host (where host is the "short name" or "alias" for the host machine)

nslookup host.oracle.com (lookup on the actual host name and domain)

nslookup 123.456.789.0 (where IP address specified is that of the actual OBIEE machine)




Steps to install and configure Loopback Adapter in Windows 7:

1.Click the Start menu.

2.Search for “cmd".

3.Right-click on “cmd” and select “Run as Administrator”

4.Enter “hdwwiz.exe”

1.In the "Welcome to the Add Hardware Wizard", click Next.

2.Select "Install the hardware that I manually select from a list (Advanced)" and click Next.

3.Scroll down and select "Network adapters" and click Next.

4.Select under Manufacturer "Microsoft" and then under Network Adapter "Microsoft Loopback Adapter" and click Next.

Tuesday, August 28, 2012

File Not Found error during db11g install

Issue seems to be caused by unzipping oracle database software into Disk1, 2,etc. folders. You do the same the 11g zip files. When it comes to install, you might get the above message. So, please make sure you unzip all the zip files into the same directory.




Example:



cd D:

mkdir db11g

mv win64_11gR2_database_1of2 d:\db11g

mv win64_11gR2_database_2of2 d:\db11g



unzip win64_11gR2_database_1of2

unzip win64_11gR2_database_2of2

cd d:\db11g

cd database

./runInstall



ORACLE HOME not found in the register ..Oracle DB 11g install

The issue seems to be caused by,




An old ORACLE_HOME had not been deinstalled/removed correctly and the following registry information still existed:



[HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\OracleMTSRecoveryService]



[HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\OracleMTSRecoveryService\Protid_0]

"Name"="HTTP"

"Host"="hostname"

"Port"="49155"



[HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\OracleMTSRecoveryService\Setup]

"NumberOfInstalls"=dword:00000001



[HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\OracleMTSRecoveryService\Setup\All Versions]



[HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\OracleMTSRecoveryService\Setup\All Versions\1]

"Version"="11.2.0.1.0"

"Home"="SOFTWARE\\ORACLE

KEY_OraDb11g_home2"



[HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\OracleMTSRecoveryService\Setup\Current Version]

"Version"="11.2.0.1.0"

"Home"="SOFTWARE\\ORACLE

KEY_OraDb11g_home2"





Please do the following,



1. Verify that:

the above registry keys exist in the Windows registry, and

they point to an old %ORACLE_HOME% which no longer exists on the server

If the registry keys do not exist or if they point to a valid %ORACLE_HOME% on the server, there is another cause for the error which needs to be investigated further. Do not perform step 2.



2. After verifying both of the above points, remove the above registry keys and perform the 11.2 installation again. The error should no longer occur.



Hope this fixes the issue

Manual and Clean Uninstall Oracle for Windows

Manual and Clean Uninstall Oracle for Windows
Warning: Editing registry may cause problems to your PC.
 If you facing problems trying to uninstall Oracle from your Windows workstation, or unable to uninstall Oracle installations cleanly and properly, the following steps may be used to uninstall all Oracle products currently install on the workstation:
 1. Uninstall all Oracle components using the Oracle Universal Installer (OUI).
2. Delete the HKEY_LOCAL_MACHINE/SOFTWARE/ORACLE key which contains registry entries for all Oracle products by using regedit.
3. Delete any references to Oracle services/components in the following registry location: HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/. Looks for key entries that starts with “Ora” which are obviously related to Oracle.
4. Reboot the workstation.
5. Delete the ORACLE_BASE directory. (i.e C:\Oracle)
6. Delete the C:\Program Files\Oracle directory.
7. Empty the temp directory.
8. Empty the recycle bin. With this, the computer is more or less clear of any Oracle components, which allows you to reinstall Oracle if needed.