Linux

1. Introduction
2. Installation
3. SQL Query in Shell Script
4. Basic commands
5. Shell Scripts


1. Introduction

Similar to DB Administrator and DB Developer we have Linux Administrator and Linux Developer. Here we deal with the concepts of Linux Developer. Unix, Linux, Windows, Mac all are operating systems.
Different peripherals: Input device; Output device (Monitor); Primary memory (RAM); Auxiliary memory (Hard disc); Controllers (8051 model); CPU (8086 model). We have to develop programs that can instructs the peripheral as per the architecture of the vendor. Lets assume we have developed one application using above hardware architecture. If another end user came to develop same application but with different hardware architecture like CPU is 8085 model then we have to write altogether new program. Change in hardware – change in program, was the earlier process. Now the invention of OS removed this problem. They developed one software that controls hardware so no need to talk to hardware directly.

→ Linux is basically same as Unix. They both have same features.
→ Unix has corporate support but Linux is developed by user contributions.
→ Linux is free open source OS based in Unix features and facilities.
→ We can consider Linux as full clone of Unix.

The basic entities of Linux are Kernel, Shell and Utilities.
→ Kernel acts as a bridge between hardware and software components. Application ⇔ Kernel ⇔ Hardware devices like CPU/ Memory/ Devices
→ Shell is an interface to communicate with OS. Shell ⇔ OS ⇔ Kernel ⇔ Hardware
We have four types of Shells. Bourne Shell (SH); C Shell (CSH); Bourne Again Shell (BASH); Korn Shell (KSH);
→ Utilities are nothing but commands


2. Installation

1. Base Machine — Base machine with Windows or MAC OS.
⇓⇑
2. Virtual Machine — Install Virtual Machine software. Ideally VM player will be used but not recommended for personal use. Its preferable to use Virtual box which is provided by Oracle. VM player should be used with high configurations, mostly in industries. Virtual box is of light weight and < 0.5 GB memory will be used. Resources from Base machine will be used by Virtual machine, making base machine slow in performance.
⇓⇑
3. Configure or deploy different virtual machines as per choice.

Steps:
1. Download Virtual box software
2. Download Extension pack
3. Download Developer days [Sand box from Oracle]
4. Install Virtual box software
5. Upload Developer days software into Virtual box.

Sandbox which is provided by Oracle has Linux, Oracle 11g and Java pre-configured.

Installation:
Type virtualbox in google >> Oracle VM Virtual box (virtualbox.org) >> Dont download the latest version (currently its 5.2) as it may have some bugs >> Left side go to downloads >> Look for ‘VirtualBox older builds’ >> Look for no longer supported >> Preferably install VirtualBox 4.3 >> Download ‘Windows hosts x86/AMD64’ under ‘VirtualBox 4.3.40 (released August 22nd 2016)’>> Download ‘Extension Pack All Platforms’ under ‘VirtualBox 4.3.40 (released August 22nd 2016)’ >> Save in some drive >> Here we are just trying to get Virtual Machine

Developer days (Sandbox — We can work on Linux, Java and Oracle) >> oracle.com >>  Trials and downloads >> More downloads >> Under ‘Servers and Storage Systems’, go to ‘VM VirtualBox’ >> Download

In Virtual Machine Virtual Box >> File >> Import >> Appliance >> Upload Sand Box >> Select Developer Day >> Open >> Next >> Modify name as Linux; Virtual disk image: Do not keep in c drive as it impacts performance. Do not change .vmdk extension >> Import >> Agree

In Virtual Machine Virtual Box >> Settings >> General >> Advanced tab >> Shared Clipboard: Bi-Directional >> Drag and drop: Bi-Directional >> System: Can increase memory upto green line in base memory. This can be altered based on base memory >> Shared folders >> Others >> e drive >> create new folder >> VB shared >> Select >> Ok >> Automount >> Ok>> Double click Linux >> Username root; Password: oracle >> For command line: Applications >> Accessories >> Terminals


3. SQL Query in Shell Script

#Start of V0.2
####################################################################
instance_name=$TWO_TASK
file_path=`sqlplus -s $username_password<< EOF
set head off
set feed off
set echo off
set line 999
 SELECT description
  FROM FND_LOOKUP_VALUES
 WHERE     1 = 1
       AND lookup_type = 'custom_lookup_type'
       AND enabled_flag = 'Y'
       AND meaning = '$instance_name';
 exit
EOF`

#Output of sql query value will be stored in file_path and to read this value use $file_path
L_OUTPUT_DIR=$file_path
L_SOURCE_FILE=$file_path/$file_name

#End of V0.2

4. Basic commands

clear screen: clear
present working directory: pwd
find files with partial name: find . -name "xx_loadapps*"
remove log files: rm *.log
remove debug files:rm *.debug
give 777 permissions: chmod 777 *.*

5. Shell Scripts

001

clear
echo "This is Message From Shell"
echo "Shell Scripting is For Reusability of Commands"
echo "With Shell Script We Can Keep Multiple Commands Together"
echo "Process Completed...Terminating The Program"

002

clear
echo "`logname` Welcome To The World of Shell Programming"
echo -e "-------------------------OoO-----------------------\n"
echo "The Sever Date is : `date -u '+%d-%m-%Y'`"
echo "`logname` You Are Currnetly Working in \"`pwd`\" Directory"
echo "The Directory Contents Are..."
echo "-----------****--------------"
echo 
ls -1 | cat -n
echo
echo "The Total Contents in The Directory Path \"`pwd`\" Are : `ls -1 | wc -l` Objects"
echo "`logname` Leaving The Process..."
echo "Returning To Shell Prompt..."

003

clear
echo "`logname` Welcome To The World of Shell Programming"
echo -e "-------------------------OoO-----------------------\n"
echo "The Sever Date is : `date -u '+%d-%m-%Y'`"
echo "`logname` You Are Currently Working in \"`pwd`\" Directory"
echo -e "\nMoving Towards The Execution of Next Process...Please Wait..."
echo "Establishing The Handle To Invoke The Program...This May Take Few Seconds..."
chmod 100 /root/myshells/shell004.sh
. /root/myshells/shell004.sh
chmod 000 /root/myshells/shell004.sh

004

echo "Request Accepted From The Previous Module..."
echo -e "Calling The Process Instructions For Execution...Please Wait...\n"
echo "The Directory Contents Are..."
echo "-----------****--------------"
echo
ls -1 | cat -n
echo
echo "The Total Contents in The Directory Path \"`pwd`\" Are : `ls -1 | wc -l` Objects"
chmod 100 /root/myshells/shell005.sh
. /root/myshells/shell005.sh
chmod 000 /root/myshells/shell005.sh

005

echo "Final Module For Exiting is Initiated...."
echo -e "Calling The Process Implementations For Releasing The Resources...Please Wait...\n"
echo "`logname` Leaving The Process..."
echo "Returning To Shell Prompt..."
echo "The Total Batch Was Executed Successfully...Leaving The Application"

006

clear
echo "`logname` Welcome To The World of Shell Programming"
echo -e "-------------------------OoO-----------------------\n"
echo "The Sever Date is : `date -u '+%d-%m-%Y'`"
echo "`logname` You Are Currnetly Working in \"`pwd`\" Directory"
echo "The Directory Contents Are..."
echo "-----------****--------------"
echo
ls -1 | cat -n &
echo
echo "The Total Contents in The Directory Path \"`pwd`\" Are : `ls -1 | wc -l &` Objects"
echo "`logname` Leaving The Process..."
echo "Returning To Shell Prompt..."

007

firstname="Srikanth"
middlename="D"
lastname="G"
echo -e "\nThe Given First Name is : $firstname"
echo -e "\nThe Given Middle Name is : $middlename"
echo -e "\nThe Given Last Name is : $lastname"
echo -e "\nThe Full Name is : $firstname $middlename $lastname"

008

v_num1=25
v_num2=10
echo -e "\nThe First Number is : $v_num1"
echo -e "\nThe Second Number is : $v_num2"
echo -e "\nThe Sum of $v_num1 And $v_num2 is : $((v_num1 + v_num2))"

009

v_num1=25
v_num2=10
echo -e "\nThe First Number is : $v_num1"
echo -e "\nThe Second Number is : $v_num2"
echo -e "\nThe Diffrence of $v_num1 And $v_num2 is : $((v_num1 - v_num2))"

010

v_num1=25
v_num2=10
echo -e "\nThe First Number is : $v_num1"
echo -e "\nThe Second Number is : $v_num2"
echo -e "\nThe Product of $v_num1 And $v_num2 is : $((v_num1 * v_num2))"

011

clear
v_num1=25
v_num2=10
echo -e "\nThe First Number is : $v_num1"
echo -e "\nThe Second Number is : $v_num2"
echo -e "\nThe Quotient of $v_num1 And $v_num2 is : $((v_num1 / v_num2))"

012

clear
v_num1=25
v_num2=10
echo -e "\nThe First Number is : $v_num1"
echo -e "\nThe Second Number is : $v_num2"
echo -e "\nThe Remainder of $v_num1 And $v_num2 is : $((v_num1 % v_num2))"

013

clear
v_num1=25
v_num2=10
echo -e "\nThe First Number is : $v_num1"
echo -e "\nThe Second Number is : $v_num2"
echo -e "\nThe Power of $v_num1 And $v_num2 is : $((v_num1 ** v_num2))"

014

clear
v_num1=25
v_num2=10
echo -e "\nThe First Number is : $v_num1"
echo -e "\nThe Second Number is : $v_num2"
echo -e "\nThe Sum of $v_num1 And $v_num2 is : `expr $v_num1 + $v_num2`"

015

clear
v_num1=25
v_num2=10
echo -e "\nThe First Number is : $v_num1"
echo -e "\nThe Second Number is : $v_num2"
echo -e "\nThe Difference of $v_num1 And $v_num2 is : `expr $v_num1 - $v_num2`"

016

clear
v_num1=25
v_num2=10
echo -e "\nThe First Number is : $v_num1"
echo -e "\nThe Second Number is : $v_num2"
echo -e "\nThe Procuct of $v_num1 And $v_num2 is : `expr $v_num1 \* $v_num2`"

 

017

018

019

020

021

022

023

024

025

026

027

028

029

030

031

032

033

034

035

036

037

038

039

040

041

042

043

044

045

046

047

048

049

050

051

052

053

054

055

056

057

058

059

060

061

062

063

064

065

functionone()
{
echo "Executing From Function One"
echo "Message From Function One"
echo "Closing The Operations in Function One"
}

functiontwo()
{
echo "Executing From Function Two"
echo "Message From Function Two"
echo "Closing The Operations in Function Two"
}

functionthree()
{
echo "Executing From Function Three"
echo "Message From Function Three"
echo "Closing The Operations in Function Three"
}

echo "Main Part of The Shell"
echo "---------***----------"
echo "Calling Fucntion One"
functionone
echo "Returned From Function One"

echo "Calling Fucntion Two"
functiontwo
echo "Returned From Function Two"

echo "Calling Fucntion Three"
functionthree
echo "Returned From Function Three"
echo "--------OOO---------"
echo "End of The Main Part"
echo "--------000---------"

 

066

functionone()
{
echo "Executing From Function One"
echo "Message From Function One"
echo "Calling Function Two"
functiontwo
echo "Returned From Function Two"
echo "Closing The Operations in Function One"
}

functiontwo()
{
echo "Executing From Function Two"
echo "Message From Function Two"
echo "Calling Function Three"
functionthree
echo "Returned From Function Three"
echo "Closing The Operations in Function Two"
}

functionthree()
{
echo "Executing From Function Three"
echo "Message From Function Three"
echo "Closing The Operations in Function Three"
}

echo "Main Part of The Shell"
echo "---------***----------"
echo "Calling Function One"
functionone
echo "Returned From Function One"

echo "--------OOO---------"
echo "End of The Main Part"
echo "--------000---------"

 

067

myclear()
{
clear
}

echo "Mein Part of The Code Will Beging Here"
echo "-----------------000------------------"
choice=
read -p "Do You Want To Clear The Screen : " choice

if [ $choice == "Yes" ]
then
myclear
else
echo "You Are Not Interested To Clear The Screen"
fi

068

clear
add()
{
echo "The Sum of $num1 And $num2 is : $(( num1 + num2 ))"
}

echo "Main Part of The Shell"
echo "---------000----------"
num1=
num2=
read -p "Enter The First Number : " num1
read -p "Enter The Second Number : " num2
add
echo "Completed The Task"

069

clear
add()
{
echo "The Sum of $1 And $2 is : $(( $1 + $2 ))"
}

echo "Main Part of The Shell"
echo "---------000----------"
num1=
num2=
read -p "Enter The First Number : " num1
read -p "Enter The Second Number : " num2
add num1 num2
echo "Completed The Task"