Wednesday, April 24, 2013

How could you maintain passwordless connection for SSH, SCP, SFTP, RSYNC commands?


Step 01:
On the client/local machine run the following commands:

mkdir -p $HOME/.ssh (if .shh does not exist.)
chmod 0700 $HOME/.ssh
ssh-keygen -t dsa -f $HOME/.ssh/id_dsa -P ''

This should result in two files, $HOME/.ssh/id_dsa (private key) and $HOME/.ssh/id_dsa.pub (public
        key).

Step 02:
Copy $HOME/.ssh/id_dsa.pub to the server.

Step 03:
On the server run the following commands:

cat id_dsa.pub >> $HOME/.ssh/authorized_keys2
chmod 0600 $HOME/.ssh/authorized_keys2

Or maybe depending on the version of OpenSSH the following commands may also be required:

cat id_dsa.pub >> $HOME/.ssh/authorized_keys
chmod 0600 $HOME/.ssh/authorized_keys

Step 04 (Optional):
An alternative is to create a link from authorized_keys2 to authorized_keys:
cd $HOME/.ssh && ln -s authorized_keys2 authorized_keys

Step 05:
On the client test the results by ssh'ing to the server:

ssh -i $HOME/.ssh/id_dsa server
Add the following $HOME/.ssh/config on the client(Optional).

Host server IdentityFile ~/.ssh/id_dsa
This allows ssh access to the server without having to specify the path to the id_dsa file as an argument to ssh each time.

How could you synchronize files between local to remote machine?


"rsync" allows you to synchronize files/directories between the local and remote system.

rsync -avz /<local_path_to_file> <remote_user>@<remote_host>:/<remote_path_to_file>

Monday, April 22, 2013

Thursday, April 18, 2013

How do you ensure the listener for a service on Oracle Network is up?

Use "tnsping" utility available in the "HOME/bin" directory of ORACLE to test if a remote listener is up (checks if the socket is reachable). This utility only ensures the availability of a listener; but not about the databases behind the listener.

Thursday, April 11, 2013

How could you convert an .XLSX format to .CSV format in Perl?

use Spreadsheet::XLSX;

my $excel = Spreadsheet::XLSX->new("Emp.xlsx");
my $sheet = ${$excel->{Worksheet}}[0];

my ($row_min, $row_max) =  $sheet->row_range();
my ($col_min, $col_max) = $sheet->col_range();

open (FH,">", "Emp.csv") or die "$!";
for my $row ($row_min..$row_max)
{
  print FH join (",", map {$sheet->get_cell($row,$_)->value()} ($col_min..$col_max));
  print FH "\n";
}
close (FH);

Thursday, April 4, 2013

How could you login into MySQL database?

mysql -h <DBHOSTNAME-u <DBUSER> -p <PASSWORD>

How could you select the first N rows in MySQL?

# Retrieve first 5 rows, equivalent to: limit 0,5
SELECT * FROM <TableName> Limit 5;

# Retrieve rows 6-10
SELECT * FROM <TableName> Limit 5,10;

What's the difference between "import" and "from...import *" in Python?

"import <ModuleName>" loads a Python module into its own namespace and restricts direct access to the members of the module. The references can be accessed by prefixing the module name followed by a dot.

import sys
sys.exit()

On the contrary, "from <ModuleName> import *" loads a module into the current namespace and allows to access those references without a prefix.

from sys import *
exit()

What is the difference between 'load' and 'require' in Ruby?

'require' looks for the library in all the defined search paths and also appends '.rb' or '.so' to the file name. It ensures that the library is included only once.

'load' needs the full name of the library and it gets loaded each time you call.