Showing posts with label UNIX. Show all posts
Showing posts with label UNIX. Show all posts

Friday, October 28, 2016

Function with arguments Shell script

Function with arguments Shell script



#!/bin/sh
# Define functions at begining of the script
test_function ()
{
echo " In test_function "
value1=$1
value2=$2
echo "value1 --> $value1"
echo "value2 --> $value2"
}

test_function1 ()
{
echo " In test_function "
value1=$3
value2=$4
echo "value3 --> $value3"
echo "value4 --> $value4"
}

test_function $arg1 $arg2
test_function1 $arg3 $arg4


Tuesday, May 10, 2016

Useful Linux Commands for oracle applications

Changing directory (cd) with variables

To resolve the environment variables (e.g. $XXX_TOP/test) passed as concurrent program argument to Host script


dirpath="$(echo $8)"
eval cd "$dirpath"
echo pwd


or to resolve path using eval

dirpath="$(echo $8)"
dirpath1=$(eval echo $dirpath)
echo "dirpath --> $dirpath1"


Call Pl-Sql procedure from shell script with out variable

 SQLVAR=`sqlplus -s $APPS_USER_ID <<ENDOFSQL  
 SET SERVEROUTPUT ON SIZE 1000000  
 whenever sqlerror exit 1;  
 declare  
 v_errorlog VARCHAR2(4000);  
 begin  
 pkg.prc(p_arg1 => $arg1, p_arg2 => $arg2, p_error_out => v_errorlog);    
 dbms_output.put_line('v_errorlog  --> '||v_errorlog);  
 end;  
 /  
 exit;  
 ENDOFSQL`  
 echo " SQLVAR output is - $SQLVAR"  




For only package call
 SQLVAR=`sqlplus -s $APPS_USER_ID <<ENDOFSQL  
 set heading off newpage 0 pagesize 0;  
 exec pkg.prc(p_arg1 => $arg1, p_arg2 => $arg2);  
 exit;  
 ENDOFSQL`  
 echo " SQLVAR output is - $SQLVAR"       


To Cut a string from the end by identifier
Cut string from the end by identifier "/" eg: /abc/def/fdf/abc.dat
OUTPUT='/abc/def/fdf/abc.dat'
 l1=$(echo $OUTPUT | awk -F"/" '{print length($0)-length($NF)}')  
 l2=`expr $l1 + 1`  
 echo "l2 $l2"  
 l3=$(echo $OUTPUT | wc -m)  
 echo "l3 $l3"  
 filename=$(echo $OUTPUT | cut -b $l2-$l3)  
 echo "filename --> $filename"  



Thursday, September 3, 2015

Check FTP/SFTP status in Shell script

Status of FTP / SFTP can be check with below code in the shell script


2>&1 -- This is going to redirect stderr to stdout


result=`ftp -nv 111.111.111.111 << EOF 2>&1
user $USER $PASSWD
put file.txt
bye
EOF`

ctr=`echo "$result" | grep "226 Transfer complete" | wc -l`

#for error check, check the return string as it's different for FTP and SFTP

err_ctr=`echo "$result" | grep "Couldn't read packet" | wc -l`


if [ $ctr -gt 0 ]
then
echo "File Transfer successful"
elif [ $err_ctr -gt 0 ]
then
echo "connection failure"
fi

Tuesday, July 21, 2015

Passing More than 9 parameters for Oracle Apps Shell/Unix Concurrent program

Oracle Apps Shell Host Concurrent program can accept more than 9 parameters but when passed 10,11 and so on to unix variable as $10 or $11 it only gets the $1 parameter which is apps username and password.

To use $10, $11 parmaters it has to be assigned as ${10}, ${11},,,

Eg: Assign 10th or 11th parameter to unix variable in shell script


tenthparam=${10}
eleventhparam=${11}

Friday, July 23, 2010

FTP in UNIX with Error Handling

Here is the script to handle FTP in UNIX. It also includes error including.

unix command $? will not capture error status, so error message has to be written to a logfile and then read.

error_log=/tmp/error_log.log
lc_server_name="your.ftp.server.name"
echo "1" $lc_server_name
ftp -i -n -d<<EOF >$error_log
open $lc_server_name
user userid password
bye
EOF
result=`grep -c 'Not connected.' error_log.log`
result1=`grep -c 'Login failed.' error_log.log`
echo $result
echo $result1
if [ ${result} -gt 0 -o ${result1} -gt 0 ]; then
echo "Connect to FTP failed"
else
echo "Connection Successful"
fi