Professional Documents
Culture Documents
Shell Scripting2
Shell Scripting2
About UNIX
UNIX OS
Files, Process and Directory
Shell Anatomy
List Commands
Directory Commands
Search and Control Commands
About UNIX
What is Unix
Unix Advantage
Unix is more flexible and can be installed on many different types of machines, including main-
frame computers, supercomputers and micro-computers.
Unix is more stable and does not go down as often as Windows does, therefore requires less
administration and maintenance.
Unix has greater built-in security and permissions
Software upgrade do not require Hardware upgrade/pre-requisites
Unix OS:
UNIX operating system is made up of three parts; the kernel, the shell and the programs.
Kernel
The kernel of UNIX is the hub of the operating system: it allocates time and memory to
programs and handles the files store and communications in response to system calls.
Shell
The shell acts as an interface between the user and the kernel
The shell is a command line interpreter(CLI)
Key Flavor's : Bourne Shell, Bash Shell and Korn Shell
Program
The commands are themselves programs
Multiple commands can be combined as a script
Unix Files, Process and Directory
Directory Structure
The file-system is arranged in a hierarchical structure, like an inverted tree. The top of the
hierarchy is traditionally called root (written as a slash / )
Anatomy and Commands
Basic Commands:
% ls -all
Commands (cont.…)
I/O Commands:
Search Commands:
Control Constructs:
The flow of control within Shell scripts is done through constructs
If..Then..Elif..Else.. Do..while..
while list
if <> then do list
elfi <> then done
else
fi
Example
Example:
#!/bin/sh
#!/bin/sh
if [ "$1" = "1" ]
count=$1
then
while [ $count -gt 0 ]
echo "Parameter value is 1"
do
elif [ "$1" = "2" ]
count=$(expr $count -1)
then
done
echo "Parameter value is 2"
elif [ "$1" = "3" ]
then
echo "Parameter value is 3"
else
echo "Parameter value is $1"
fi
Commands (cont.…)
Control Constructs:
For Case
for variable in word ... case word in
pattern) list ;;
do list ...
esac
done
Example:
Example:
#!/bin/sh !#/bin/sh
fruitlist="Apple Pear Tomato Peach Grape" case $1
in
for fruit in $fruitlist 1) echo 'First Choice';;
2) echo 'Second Choice';;
do *) echo 'Other Choice';;
if [ "$fruit" = "Tomato" ] || [ "$fruit" = "Peach" ] esac
then
echo "I like ${fruit}es"
else
echo "I like ${fruit}s"
fi
done
Commands (cont.…)
Functions: Anatomy:
name() {
Variable declaration
commands
var1=„Hello World‟;
}
Exit status
exit 0
Day - 2
Topics
vi Editor
FTP
SSH (including SCP and SFTP)
Unix Mailer - mailx
Registering a Host Program
Reading a DB value by launching SQL Plus
Executing a DB Procedure
Vi Editor
vi Editor:
vi is a screen-oriented text editor originally created for the Unix operating
system
Inbound/Outbound File Transfer - FTP
FTP:
File Transfer Protocol (FTP) is a network protocol used to copy a file from one computer
to another over the Internet or LAN
Basic Commands
Open – connect to remote server FTP port
open <remote_machine(Hostname)/IP>
lcd – Local current directory in the remote
server
pwd – present working directory in the
local server
FTP (cont…)
put
put <filename>
mput <filename*.*>
get
get <filename>
mget <filename*.*>
Transfer Mode
ascii For text file like data files and Shell Scripts
bin For executable like .rdf, .fmx etc.
SSH
SSH:
SSH, which is an acronym for Secure SHell, was designed and created to
provide the best security when accessing another computer remotely.
Not only does it encrypt the session, it also provides better authentication
facilities, as well as features like secure file transfer, X session forwarding,
port forwarding.
vs
SSH (cont.…)
Secure Copy:
SCP is a means of securely transferring computer files between a local host and a
remote host or between two remote hosts. It is based on the Secure Shell (SSH)
protocol.
SFTP:
SFTP is a network protocol that provides file access, file transfer, and file management
functionalities.
Key features :
1. Delete remote file
2. Execute a shell in the remote
3. Interactive
Unix Mailer
mailx:
mailx: An utility to send and receive email. SMTP/mail server setting has to be pre-
configured prior to mailx usage
Options:
1. Mail body
2. Attach files
3. Add cc and bcc
Example1:
mailx –s “Test Mail from Unix System” john@abc.com
Example2:
(echo "${MAIL_BODY}" ";uuencode ${FILE1};uuencode ${FILE2}") | mailx -s
“${MAIL_SUBJECT}" "${EMAIL}"
Unix Capabilities in Oracle Apps Environment
Why fndcpesr? - Otherwise we need to read the concurrent program parameters using cut commands
System parameters:
$1 apps_username_pwd [e.g. apps/appspwd]
$2 userid
$3 username
$4 request_id
User parameters:
From $5 to till defined
Registering as Host Program(cont.…)
User parameters: Set Program completion status:
From $5 to till defined At the end of the script use exit command
Examine the data and build the Control file accordingly and load the data into
the table
Example:
cd $CUSTOM_TOP/data
for file in sample*.dat
do
sqlldr userid=$login control=$CUSTOM_TOP/bin/sv_test.ctl
data=$CUSTOM_TOP/data/$file
mv $CUSTOM_TOP/data/$file $CUSTOM_TOP/archive/$file
done
CONCSUB
CONCSUB
Concurrent program can be submitted from Shell script through concsub utility
shipped by Oracle
Example:
cd $FND_PATH
v_concreq=`./CONCSUB $ORA_USER_PASS $APPLN_NAME $RESP_NAME1 $USER_NAME
WAIT=Y CONCURRENT SQLAP "APXMCCDF3" $CARD_PROGRAM_ID ${1}`
SSH Password – less Login
SSH Password Less Login steps:
File Cryptography
Sensitive data requires file encryption/decryption to maintain security when it is
transferred through a computer network
PGP/GPG
Pretty Good Privacy (PGP) / GNU Privacy Guard is a data encryption and decryption computer
program that provides cryptographic privacy and authentication for data communication.
PGP is a CPU licensed software and GPG is GPL
PGP has got product support and GPG do not have support
PGP is recommended for enterprise level encryption/decryption
Encrypt Command:
/opt/pgp/bin/pgp --encrypt ${FILE_NAME}.txt --output ${FILE_NAME}.pgp --overwrite remove --
passphrase ${PGPPASSPHRASE} -r ${PGP_RECIPIENT}
Decrypt Command:
/opt/pgp/bin/pgp --decrypt --input ${FILE_NAME} --output ${DECRYPT_FILE_NAME}.dat --overwrite
remove --passphrase ${PGPPASSPHRASE}
Host Program – Set Program status to Complete -
Warning
Host Program completion status can be set using exit command.
exit 1 In this case, program status will not set to Complete – Error
Work around:
sqlplus -s $p_usr_pwd <<-EOF
set feedback off
declare
l_stat Boolean;
l_session_id Number;
begin
fnd_global.initialize(session_id => l_session_id, user_id => fnd_global.user_id, resp_id => fnd_global.resp_id
, resp_appl_id => fnd_global.resp_appl_id, security_group_id => null
, site_id => null, login_id => null, conc_login_id => null
, prog_appl_id => null, conc_program_id => null, conc_request_id => $p_req_id, conc_priority_request => null);
l_stat := fnd_concurrent.set_completion_status('WARNING','Completed in Warning. Review log for details.');
commit;
end;
/
exit;
EOF
References
Reference URL‟s
http://www.unix.org
http://www.tutorialspoint.com/unix/
http://en.wikipedia.org/wiki/Public-key_cryptography
http://en.wikipedia.org/wiki/Secure_Shell
http://en.wikipedia.org/wiki/Mailx
Q&A
Q&A
Thank You
www.hcl.com