Showing posts with label Useful commands. Show all posts
Showing posts with label Useful commands. Show all posts

Monday, 7 March 2016

Unix - Scripting Useful commands

Basic Steps to Create Host Concurrent Program 1. Create a ".prog" File
 2. Move the File to Server in any Custom TOP "bin" Folder (Tools Winscp / Filezilla)
 3. Execute the Below commands oderly maner
     3.1 Putty> cd $XXCUSTOM_TOP/bin
         -- Here the Custom TOP is the File Location TOP 
     3.2 Putty> dos2unix sample.prog
     3.3 chmod 755 sample.prog
     3.4 Putty> ln -s $FND_TOP/bin/fndcpesr sample
          -- Here the File name with out .prog Extension
          -- We are creating the Softlink to our File
     3.5 Add continue to create concurrent program Excutable and Program but the Executable type is "HOST"


Sample Commands:

1. Commenting any line in UNIX by using hash(#)
   # this is commented
2. Getting the Oracle Standard Parameters
   #user/bin/ksh
   ORAUSER_PASSWD=$1
   USER_ID=$2
   USER_NAME=$3
   REQUEST_ID=$4
 
3. Below command is used to print to Log File
   echo "Hi"
  
4. In Unix we can create Variables directly when evere we need and we can run any sql/plsql script directly
   like a block
 
Unixvariable =  `sqlplus -S  ${ORAUSER_PASSWD}<< ENDOFSQL
    set feedback off
    set serveroutput on
    exec APPS.Package_name.procedure_name(parameters);
    exit
    ENDOFSQL`
echo "${Unixvariable}"

5. I have text containg three value seperated by comma(,)
   -- Unixvariable = '123,234,456'
   i want to store every value into different variable

value1 = `echo $Unixvariable | awk -F"," '{print $1}'`
value2 = `echo $Unixvariable | awk -F"," '{print $2}'`
value3 = `echo $Unixvariable | awk -F"," '{print $3}'`

6. if there is any spaces in text we can remove
 newvalue1 = `echo $value1 | sed -e 's# ##g'`

7. UNIX is power full we can track each and every step, below function works like SQL%NOTFOUND in Oracle
    here i have written script for connecting to SFTP Server, if the connection is success no issue, if connection is not established due to any problem we can track this failure by using  below command
if [ ${?} -ne 0 ]

it check most recent command is executed successfully / not.

connection=`sftp "${vendor_username}"@"${vendor_host}" << END
    cd "${Direcoty Address}"
    lcd "$CUSTOM_TOP/bin"
    GET *.csv
    quit
    END`
#Check Log File Exist Before Validation Start
if [ ${?} -ne 0 ]
then
    echo "Unable to connect to destination server."
echo "${connection}"
    exit 2
    fi

8. We can call the SQL*LOADER Programs from UNIX Script easily

   CONTROL_STATUS=`sqlldr userid=${ORAUSER_PASSWD}            control=$CUSTOM_TOP/bin/control_file.ctl data=datafile.csv log=$APPLCSF/log/datafile.log bad=$APPLCSF/log/datafile.bad<< ENDOFSQLLDR
   ENDOFSQLLDR`
   echo "${CONTROL_STATUS}"

9. We can capture the date into variable

   currdate = `date +%d_%m_%g_%H_%M_%S`

10. We can create Files into the server using unix script in an easy manner
    `sqlplus -S ${ORAUSER_PASSWD} >> Kranthi.csv <<EOF
set head off;
set pages 0;
set linesize 2000;
set feedback off;
SELECT  'Emp Number'||','||
   'Emp Name' ||','||
     'Emp Sal'
from dual
/

exit
EOF`

11. Move the All ".csv" Files from Source Directory to Destination Directory
    cd "Source_Direcoty"
    find ./ -type f -name "*.csv" -print | xargs -l56 -i mv -f {} "Destination_Directory"

12. We can create Functions and we can pass parameters to Functions, here i am passing one parameter to Function
    Delete_Files()
    {
    cd $1
    echo "${PWD}"
    fileArray=($(find *.csv -mtime +10))
    filescount=${#fileArray[@]}
    for (( i=0; i<${filescount}; i++ ));
    do
    echo "${fileArray[$i]}"
    rm -f ${fileArray[$i]}
    echo "File deleted from Folder"=${fileArray[$i]}
    done
   }
   echo "Searching Files in bin direcory older than 10 Days...."
   Delete_Files $CUSTOM_TOP/bin

13. We can apply file permission(777) to all subfolders by using this command
    chmod -R 777 *
 
      
15. Control Structres in UNIX
 
     if test condition
      then
      statements;
fi

if [condition];
then
     statements;
     else
     statements;
     fi

if [condition];
then
   statements;
     elif
     then
     statements;
else
      statements;
     fi


     for expression
     do
  statements;
     done

16. File Comparisions
    -eq equal to
-ne not equal to
-lt less than
-le less than or equal to
-gt greater than
-ge greater than or equal to

BI Publisher Commands

<?start:body?>
<?end body?>
The text occurring before the <?start:body?> tag  treated as a Header.
The text occurring in between   <?start:body?>  and <?end body?>  treated as a Body.
The text occurring after the <?end body?>  treated as a footer.


<?xdoxslt:sysdate()?>
<?xdoxslt:sysdate('DD/MM/YY HH:MI:SS')?>

To get the Date in RTF Report, For Displaying Current System Date in Layout we have to use tis Tag.


<?for-each@section:G_DEPTNO?>
Use @section to split the page at every deptno level.
The problem with @section is if we don’t have data the output will not open.
And we can’t use @section more than once per a layout.

<?split-by-page-break:?>
We can use split-by-page-break , how many times we want in a single layout.
We have to use this tag exactly before end tag of any group
Don’t use the split-by-page-break in the same line of data row.

url:{concat('${OA_MEDIA}','/',IMAGE_FILE)}
For this you have to do below setps:
1.   Insert a dummy image in your template.
2.   In Microsoft Word's Format Picture dialog box select the Web tab. Enter the following syntax in the Alternative text region to reference the image URL:
url:{'http://image location'}
For example, enter: url:{'http://www.oracle.com/images/ora_log.gif'}

If we want to display main group elements in the sub group like “empno” in “dept” group. We have to place the ../../ before the tag (../../empno)

<?start@last-page:body?>< ?end body?>
If you want to display the total in last page use this command

<?if@row:SAL> 3000?>
 <xsl:attribute  xdofo:ctx="incontext" name="background-color">red
 The Color will apply to entire row by using “@row” attribute.
If you remove the “@row” the color will apply to that single column only.
The Xdofx:ctx has two values 1.incontext 2.block

<?if:SAL> 2500 ?>
<?end if?>
If you want to hide the Rows use this command in Group level

<?init-page-total: pst?>
<?add-page-total:pst;'SAL'?>
<?show-page-total:pst;'C9G990D00';'(C9G990D00)'?>
to show page wise totals
If you are using sum(sal) function in the any rtf file, if at least one sal field contains salary null the output will not generated it will give an error. To get a correct result you have to handle null columns like below
Use sum(sal[.!=’’])

create a variable
<?xdoxslt:set_variable($_XDOCTX, 'V_NUM', 0)?>
incremet / decrement variable
<?xdoxslt:set_variable($_XDOCTX, ‘V_NUM’, xdoxslt:get_variable($_XDOCTX, ‘V_NUM’) + 1)?>
display variable
<?xdoxslt:get_variable($_XDOCTX, 'V_NUM')?>

<?for-each-group:CD;COUNTRY?>
<?for-each-group:current-group();YEAR?>
<?for-each:current-group()?>
<?end for-each?>
<?end for-each-group?>
<?end for-each-group?>


Number Formatting


<?xdoxslt:xdo_format_number_l(100000,'999G999D99','EN-us')?>

O/P:-  100,000.00

<?xdoxslt:xdo_format_number_l(100000,'999G999D99','DE-de')?>

O/P:-   100.000,00


Repeating the Output Based on the String Length

<?xml version="1.0" encoding="WINDOWS-1252" ?>
<juvva>
<test>kranthi</test>
</juvva>


<?xdoxslt:set_variable($_XDOCTX, 'cnt',string-length(test))?>
<?for-each:xdoxslt:foreach_number($_XDOCTX,1,xdoxslt:get_variable($_XDOCTX, 'cnt'),1)?>
XYZ
<?end for-each?>

O/P :- XYZ
       XYZ
  XYZ
  XYZ
  XYZ
  XYZ
  XYZ
  
Repeating the Output Data as needed

<?xml version="1.0" encoding="WINDOWS-1252" ?>
<ROWSET>
<ROW>
<DEPT>Z1</DEPT>
<DATA>2112</DATA>
</ROW>
<ROW>
<DEPT>A1</DEPT>
<DATA>7985</DATA>
</ROW>
<ROW>
<DEPT>B1</DEPT>
<DATA>8452</DATA>
</ROW>
<ROW>
<DEPT>B2</DEPT>
<DATA>2159</DATA>
</ROW>
</ROWSET>


<?for-each@section:xdoxslt:foreach_number($_XDOCTX,1,2,1)?>
<?for-each:/ROWSET/ROW?> <?DEPT?> <?end for-each?>
<?end for-each?>

O/P :- Z1
       A1
       B1
       B2
       Z1
       A1
       B1
       B2
  
-- @section Gives the data in new page


We can also use below syntax for before and after

<xsl:attribute name="break-before">page</xsl:attribute>
<xsl:attribute name="break-after">page</xsl:attribute>


 Conditional pagebreak, use below syntax. 
 Here we are inserting page-break if value of variable no_of_lines_per_page is equal to total records in loop inner_group. Variable is always referred by $ in XSL

<xsl:if xdofo:ctx="inblock" test="$no_of_lines_per_page=count($inner_group)"> 
<xsl:attribute name="break-before">page</xsl:attribute>
</xsl:if>


Multiple Date Formats
------------------------
<?xdoxslt:to_char(DATECREATED,'DD-MON-YYYY')?> 
<?format-date:hiredate;'SHORT'?>
<?format-date:hiredate;'YYYY-MM-DD'?> 
<?xdoxslt:sysdate(“DD-Mon-YY”)?>
<?initial-page-number:'AUTO'?>
<?initial-page-number:PAGESTART?>
<?initial-page-number:$PAGESTART?> --Parameter


Number Format
---------------

<?choose:?><?when:./PERIOD_NET_CR!=""?><?format-number:./PERIOD_NET_CR;'99G990D00'?><?end when?><?otherwise:?><?format-number:0.00;'0D00'?><?end otherwise?><?end choose?>

<?xdoxslt:set_variable($_XDOCTX, ’CC1’, ./ACCOUNTING_CODE_COMBINATION)?>
<? xdoxslt:get_variable($_XDOCTX, ’CC1’)?>


Useful fusion query for User access

  Table FUN_USER_ROLE_DATA_ASGNMNTS is used for “Manage data access for users”. it will store use and role assignment to data security. Tabl...