Monday, November 30, 2009

Unix/Linux Shell Scripting

This short post is about some tips/tricks in Shell Scripting.

1. Invoke PLSQL/SQL from Shell
Shell START

#!/bin/bash

param_one="$1"
param_two="$2"

if [ ${#1} == 0 ]
then
param_one="null"
fi

if [ ${#2} == 0 ]
then
param_two="null"
fi

echo "one " $param_one
echo "two "$param_two

CHECK_THIS=`sqlplus -s apps/apps@appsDB
<< ! 
set term off 
set head off 
set pages 0 
set feedback off 
BEGIN 
  INSERT_LOG(p_mesg1 => $param_one,p_mesg2=>$param_two);
END;
/
!
`
echo $CHECK_THIS
Shell END

.

2. Print new line in Shell Script
echo $@
.

3. Debug Shell Script
Put below line at the start of the script
#!/bin/bash -x
.

4. Find files, example of search for the string "ERROR" in all xml files in the current directory and all sub-directories
find . -name "*.xml" -exec grep "ERROR" '{}' \; -print
.

5. Find and list files
$find . -name "XXFILENAME" -type f -ls
.

6. More to come..

No comments: