Install JDK9 on Linux Mint

In this article we will see how we can install JDK9 i.e. Oracle Java 9 on Linux mint version.

Execute the below commands in sequence on Linux Mint machine:

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java9-installer

While executing the above you will see the get the aggrement options where we need to click ok and proceed. After the above steps setup Java environment using PPA repository

Exeucte the below command to install the package :

sudo apt-get install oracle-java9-set-default

Now let us check our Java version by exeucting the below commands:

oracle@dev-VirtualBox ~ $ java -version
java version "9.0.4"
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)
oracle@dev-VirtualBox ~ $ 

Thank you for reading my blog , please feel free to leave me some feedback or to suggest any future topics.

Looking forward to hear from you – Swadhin Ray (Sloba) -( LinkedIn ) ( Twitter )

 

Advertisements

0% [Connecting to archive.ubuntu.com ] Error

I encountered this error while using “apt-get” command on  my Linux mint server and it got stuck for 12-3 mins.

Here is the details on my error that I faced :


dev@dev-VirtualBox /etc $ sudo apt-get install alien
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
autoconf automake autopoint autotools-dev debhelper debugedit dh-autoreconf
dh-strip-nondeterminism libfile-stripnondeterminism-perl librpm3
librpmbuild3 librpmio3 librpmsign3 libtool po-debconf rpm rpm-common
rpm2cpio

.........

......

.........

0% [Connecting to archive.ubuntu.com (2001:67c:1560:8001::14)] [Connecting to

The issue is on the IPv6 taking more time to execute. Now let us check if my IPv6 is enabled or disabled. Based on the output we will see if we need to disable.


dev@dev-VirtualBox /etc $ cat /proc/sys/net/ipv6/conf/all/disable_ipv6
0
dev@dev-VirtualBox /etc $

If we get the output “0” then my IPv6 is enabled and if we get “1” then it is disabled.  So in my case I have to disable it. Let us see how we can disable it . And try to rerun my command where I got stuck.

To disable please execute the below commands and after that reboot the machine:


dev@dev-VirtualBox /etc $ echo "#disable ipv6" | sudo tee -a /etc/sysctl.conf
#disable ipv6
dev@dev-VirtualBox /etc $ echo "net.ipv6.conf.all.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf
net.ipv6.conf.all.disable_ipv6 = 1
dev@dev-VirtualBox /etc $ echo "net.ipv6.conf.default.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf
net.ipv6.conf.default.disable_ipv6 = 1
dev@dev-VirtualBox /etc $ echo "net.ipv6.conf.lo.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf
net.ipv6.conf.lo.disable_ipv6 = 1
dev@dev-VirtualBox /etc $

I have rebooted my system now let us check what is the output I am getting :


oracle@dev-VirtualBox ~ $ cat /proc/sys/net/ipv6/conf/all/disable_ipv6
1
oracle@dev-VirtualBox ~ $

Now we can see that my IPv6 is disabled , so let us try to execute my initial “apt-get” command


dev@dev-VirtualBox ~ $ sudo apt-get update
Hit:1 http://archive.canonical.com/ubuntu xenial InRelease
Ign:2 http://packages.linuxmint.com sylvia InRelease
Hit:3 http://packages.linuxmint.com sylvia Release
Hit:4 http://archive.ubuntu.com/ubuntu xenial InRelea

...

...

..

Get:22 http://archive.ubuntu.com/ubuntu xenial-updates/universe Translation-en [233 kB]
Get:23 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [16.2 kB]
Get:24 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse i386 Packages [15.3 kB]
Fetched 4,825 kB in 1s (2,621 kB/s)
Reading package lists... Done
dev@dev-VirtualBox ~ $

So we can see that we are now able to install the packages without any issues.

 

Thank you for reading my blog , please feel free to leave me some feedback or to suggest any future topics.

Looking forward to hear from you – Swadhin Ray (Sloba) -( LinkedIn ) ( Twitter )

 

 

Append row into a CSV file on SFTP

In this post I am going to show how we can append a row into CSV file using simple bash command.

To demonstrate this I am using Linux virtual machine, the OS is on Mint 18.3 64bit.  First me create a sample file on my Linux Machine as like below.

dev@dev-VirtualBox ~/Desktop/CSV $ pwd
/home/dev/Desktop/CSV
dev@dev-VirtualBox ~/Desktop/CSV $ ls
dev@dev-VirtualBox ~/Desktop/CSV $ cat <<EOF >sample.csv
> COL1,COL2,COL3
> 1,FIRST_LINE,18-JAN-2018
> EOF
dev@dev-VirtualBox ~/Desktop/CSV $ ls
sample.csv
dev@dev-VirtualBox ~/Desktop/CSV $

Once the file is created it will look something like below:

image

Now let us think that this file is on a SFTP server where we need to connect and append another line without renaming or changing the file format.

Login to the server


login as: dev
dev@10.0.0.203's password:
Welcome to Linux Mint 18.3 Sylvia (GNU/Linux 4.10.0-38-generic x86_64)

* Documentation:  <a href="https://www.linuxmint.com/">https://www.linuxmint.com</a>
Last login: Tue Jan 23 09:55:52 2018 from 10.0.0.203
dev@dev-VirtualBox ~ $ ls
Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos
dev@dev-VirtualBox ~ $ cd Desktop/
dev@dev-VirtualBox ~/Desktop $ ls
CSV
dev@dev-VirtualBox ~/Desktop $ cd CSV/
dev@dev-VirtualBox ~/Desktop/CSV $ ls
sample.csv

So now we can login to the server.

Method 1: Now let us execute the below line to insert or append a new row to the existing CSV file i.e. sample.csv:


dev@dev-VirtualBox ~/Desktop/CSV $ sed -i.bak 1i"2,Second_Line,18-JAN-2018" sample.csv
dev@dev-VirtualBox ~/Desktop/CSV $

Once the above line is executed we will see the row is inserted but not at the end but at the beginning.

image

Now how we can append the line at the end .


dev@dev-VirtualBox ~/Desktop/CSV $ pwd
/home/dev/Desktop/CSV
dev@dev-VirtualBox ~/Desktop/CSV $ ls
sample.csv
dev@dev-VirtualBox ~/Desktop/CSV $ cat sample.csv
COL1,COL2,COL3
1,FIRST_LINE,18-JAN-2018
dev@dev-VirtualBox ~/Desktop/CSV $ sed -i -e "\$a2,Second_Line,18-JAN-2018" sample.csv
dev@dev-VirtualBox ~/Desktop/CSV $ cat sample.csv
COL1,COL2,COL3
1,FIRST_LINE,18-JAN-2018
2,Second_Line,18-JAN-2018
dev@dev-VirtualBox ~/Desktop/CSV $

 

The line used to insert the row/ append the row at the end is :

sed -i -e "\$a2,Second_Line,18-JAN-2018" sample.csv

Method 2: Now let us check how we can use echo to insert the line at the end.


dev@dev-VirtualBox ~/Desktop/CSV $ echo "3,Third_Line,18-JAN-2018" >> sample.csvdev@dev-VirtualBox ~/Desktop/CSV $ cat sample.csv
COL1,COL2,COL3
1,FIRST_LINE,18-JAN-2018
2,Second_Line,18-JAN-2018
3,Third_Line,18-JAN-2018
dev@dev-VirtualBox ~/Desktop/CSV $

Method 3: Append using a simple python programming


dev@dev-VirtualBox ~/Desktop/CSV $ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> with open('sample.csv', 'a') as file:
...     file.write('4,Fourth_Line,18-JAN-2018')
... ;
   File "<stdin>", line 3
     ;
     ^
SyntaxError: invalid syntax
>>> with open('sample.csv', 'a') as file:
...     file.write('4,Fourth_Line,18-JAN-2018\n');
...
>>> exit()

Finally, the file will look like as below:


dev@dev-VirtualBox ~/Desktop/CSV $ cat sample.csv
COL1,COL2,COL3
1,FIRST_LINE,18-JAN-2018
2,Second_Line,18-JAN-2018
3,Third_Line,18-JAN-2018
4,Fourth_Line,18-JAN-2018

dev@dev-VirtualBox ~/Desktop/CSV $



 

image

 

To automate the process you can create a script and try to pass the row as a input to the file while calling the script.

 

Thank you for reading my blog , please feel free to leave me some feedback or to suggest any future topics.

Looking forward to hear from you – Swadhin Ray (Sloba) -( LinkedIn ) ( Twitter )

 

Reorder the columns in CSV file using Python

Many time we work on files to load or process the flat files. In this post, I am showing if we receive the file but the columns are not in order then how to rearrange them in the right format. There are multiple ways to handle this but here I am using a simple python code which will reorder my columns.

Say for example my right order of my file should be as below:

 empno, ename, sal 

But say I receive a file with

 sal, ename, empno 

image

Now here is the simple python script which will change the file into right order :

import csv

with open('file2.csv', 'r') as infile, open('file2_modified.csv', 'a') as outfile:
fieldnames = ['empno','ename','sal']
writer = csv.DictWriter(outfile, fieldnames=fieldnames)
writer.writeheader()
for row in csv.DictReader(infile):
writer.writerow(row)

Save the above code as “target_file_format.py” or anyname you want.

Execute the python script , and check the result.

image

You can modify the code in various ways as per your need.

Thank you for reading my blog , please feel free to leave me some feedback or to suggest any future topics.

Looking forward to hear from you – Swadhin Ray (Sloba) -( LinkedIn ) ( Twitter )

Access Windows shared directory from Ubuntu 16.04.3 LTS VirtualBox Guest

In this post I am going to show how to access windows shared directory from Ubuntu 16.04.3 LTS virtual machine.

First create a directory on the host. For example I am creating one directory called on my E drive [ My host is Windows 7 ] .

Now open VirtualBox go to settings of your Ubuntu guest, under shared section add your directory that was created with full permission. Once this is completed login to Ubuntu virtual machine and type the below:

 sudo usermod -aG vboxsf $(whoami) 

Executed on my machine as like below:

sloba@sloba-VirtualBox:~$ sudo usermod -aG vboxsf $(whoami)
[sudo] password for sloba:
sloba@sloba-VirtualBox:~$ reboot

After that reboot your Ubuntu machine you can access the shared drive as shown below.


sloba@sloba-VirtualBox:~$ ls
Desktop Downloads Music Pictures Templates
Documents examples.desktop oraInventory Public Videos
sloba@sloba-VirtualBox:~$ cd /media/
sloba@sloba-VirtualBox:/media$ ls -lrt
total 12
drwxrwx--- 1 root vboxsf 0 Jan 22 21:12 sf_vmshare

sloba@sloba-VirtualBox:/media$ cd sf_vmshare/
sloba@sloba-VirtualBox:/media/sf_vmshare$

 

Thank you for reading my blog , please feel free to leave me some feedback or to suggest any future topics.

Looking forward to hear from you – Swadhin Ray (Sloba) -( LinkedIn ) ( Twitter )

 

 

Bash Scripting

Bash (Bourne Again SHell )is a Unix shell or we can say it’s a command line interpreter which provides a traditional user interface for UNIX Operating System and for other similar Unix systems. This was the replacement for Bourne shell and was released in year 1989. This is distributed GNU OS as a default shell on Unix or LINUX operating system. This is POSIX shell with more number of extensions.

We can execute the BASH using command line or writing a series of commands on a text file and save it with “.sh” extension. If we want to execute any BASH script then first we have to provide the execute permission and if we don’t provide the permission or forgot to provide then it will simply given an error message by saying “Permission denied”.

For example here is my very simple BASH script which is named as “hello.sh” .

#!/bin/bash
# Sample Bash script
echo Hello Sloba!

Now let us see if we have the execute permission or not for the above script.

login as: sloba
sloba@**************'s password:
Welcome to Linux Mint 17.2 Rafaela (GNU/Linux 3.16.0-38-generic x86_64)

Welcome to Linux Mint
 * Documentation:  http://www.linuxmint.com
Last login: Sun Oct 11 18:29:48 2015 from 192.168.2.8
sloba@sloba-VirtualBox ~ $
sloba@sloba-VirtualBox ~/Desktop/BASH $ ls -lrt
total 4
-rw-rw-r-- 1 sloba sloba 50 Nov 17 09:25 hello.sh
sloba@sloba-VirtualBox ~/Desktop/BASH $

 

And below is the screen shot from the server using WinScp tool.

image

 

Now we see that we don’t have the execute privileges on the script but let us go ahead and try to run it.

sloba@sloba-VirtualBox ~/Desktop/BASH $ ./hello.sh
-bash: ./hello.sh: Permission denied
sloba@sloba-VirtualBox ~/Desktop/BASH $

Now we can see that we get an error with “ Permission denied ”. Now let us try to provide the execute privilege  to our script and then run it.

ls -lrt
total 4
-rwxrwxrwx 1 sloba sloba 50 Nov 17 09:25 hello.sh
sloba@sloba-VirtualBox ~/Desktop/BASH $ ./hello.sh
Hello Sloba!
sloba@sloba-VirtualBox ~/Desktop/BASH $

Finally we are able to get the result of the simple hello script after giving the execute privilege, in general 755 permission is provide to execute the script or modify by the owner .

To execute the script we have seen that we use “./” before the script . The Dot means it is pointing to the current directory to find the script and execute it. And if we keep the script any other directory and we can use something like this “./<<path>>/hello.sh” .

We also see from the script that the first line starts with “#!” , this is called Shebang . The hash and exclamation mark is the character sequence which is basically referred as shebang , after that what we see is the interpreter path which should be used to execute the program for the next set of lines in the file.

 

Thank you for reading my blog . Please feel free to leave me some feedback or to suggest any future topics.

Looking forward to hear from you – Swadhin Ray (Sloba) -( LinkedIn ) ( Twitter )

SFTP from PLSQL

In this blog I am going to use a simple program to SFTP files from my database server to any target machine using SFTP. To demonstrate this I am using two servers one where I have Oracle installed and another server where SFTP is enabled.

SFTP basically means a protocol in which we can move one file to any other server in secured way. The full form is “Secure File Transfer Protocol” , this is protocol which is packaged with SSH.

To achieve this we have to do some prerequisites like creating one shell script , and follow to create a function called “msi_extprocsh” from my earlier blog.

Link as to follow the steps to create the function:

https://slobaexpert.wordpress.com/2015/09/10/executing-linux-command-from-oracle-plsql/

Once you have complete the steps shown on the link , create a folder called “sftp”  on your database server “/home/oracle/app/” .

And create a file called “sftp.sh” under path “”  with the below code:

#!/usr/bin/expect

set timeout -1

if { $argc != 6 } {
    puts "Usage $argv0 host user pass cd lcd file "
    exit 1
}

set host [lindex $argv 0]
set user [lindex $argv 1]
set pass [lindex $argv 2]
set cd [lindex $argv 3]
set lcd [lindex $argv 4]
set file [lindex $argv 5]

spawn sftp -oStrictHostKeyChecking=no -oCheckHostIP=no $user@$host
expect *assword:

send "$pass\r"
expect sftp>

send "cd $cd\r"
expect sftp>

send "lcd $lcd\r"
expect sftp>
send "put $file\r"

send "exit\r"
expect eof

The above file contains 6 parameters where we need to pass the host name of target server where we want to move the file along with username & password .  Set the local and report directory where we want to place the file.

Now under path “/home/oracle/app/sftp” create a sample file called “Hello.txt” and save the file with some sample text like :


[oracle@DBserversftpsftp]$ pwd
/home/oracle/app/sftp
[oracle@DBserversftp]$ cat Hello.txt
This is a sample file[oracle@DBserversftp]$

Now lets login to our target server where we want to place the file :

login as: root
root@TargetServer's password:
Last login: Thu Sep 10 11:27:44 2015 from TargetServer
[root@TargetServer ~]# cd Desktop/sftp/
[root@TargetServer sftp]# pwd
/root/Desktop/sftp
[root@TargetServer sftp]# ls
[root@TargetServer sftp]#

We can see that there is no file present on the location

Now let’s run the PLSQL block to place the “Hello.txt” file on the target server.

DECLARE

        l_file_name       VARCHAR2(4000) := 'Hello.txt'; --file name 
        retval            NUMBER;
        l_sftp_prog       VARCHAR2(100) := 'cd /home/oracle/app/sftp; ./sftp.sh';
        l_sftp_host       VARCHAR2(100) := 'hostname';
        l_sftp_user       VARCHAR2(100) := 'username';
        l_sftp_pass       VARCHAR2(100) := 'password';
        l_sftp_path       VARCHAR(500) := '/root/Desktop/sftp/'; -- target directory to put the file
        l_local_file_path VARCHAR2(500) := '/home/oracle/app/sftp/'; -- local file path 
        l_sftp_command    VARCHAR2(500);

BEGIN

        l_sftp_command := l_sftp_prog || ' ' || l_sftp_host || ' ' || l_sftp_user || ' ' ||
                          l_sftp_pass || ' ' || l_sftp_path || ' ' || l_local_file_path || ' ' ||
                          l_file_name;

        dbms_output.put_line(l_sftp_command);

        retval := msi_shell(l_sftp_command);

        dbms_output.put_line(retval);

END;

Check the target server :

[root@TargetServer sftp]# ls
[root@TargetServer sftp]# ls
Hello.txt
[root@TargetServer sftp]# pwd
/root/Desktop/sftp
[root@TargetServer sftp]#
[root@TargetServer sftp]# cat Hello.txt
This is a sample file[root@TargetServer sftp]#

Now we can see that the file is moved using SFTP protocol through PLSQL code. Basically we are calling the bash script to do the SFTP and PLSQL code is calling the script by passing right set of parameter from Oracle.

Thank you for reading my blog , the reference is taken from OTN . Please feel free to leave me some feedback or to suggest any future topics.

Looking forward to hear from you – Swadhin Ray (Sloba) -( LinkedIn ) ( Twitter )