달력

4

« 2024/4 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
2009. 7. 8. 20:08

오랜만의 쉘 스크립트 그거/Tech2009. 7. 8. 20:08


# 프로시저의 결과를 쉘 스크립트에서 받기
#!/bin/sh

# run sqlplus with a 'callProc.sql' file
# in 'callProc.sql' file, print result of procedure by running 'dbms_output.put_line'
# get an output message by using 'grep'

# usage
# sqlplus <id>/<pw> @<sqlfile> | grep "<keyword>"

sqlplus hdmfdbm/hdmfdbm @callProc.sql | grep "l_num1="

####### sql file - callProc.sql #####################
#
# set serveroutput on
# declare
#   l_num1 number := 100;
#   l_num2 number := 101;
# begin
#   calc(l_num1, l_num2);
# end;
# /
# quit
#
####### sql file - callProc.sql #####################

####### procedure - calc ##########################
# create or replace procedure calc(
#   p_parm1 in out number,
#   p_parm2 in out number) as
#   test_temp number;
# begin
#   test_temp := p_parm1;
#   p_parm1 := p_parm2;
#   p_parm2 := test_temp;
#   dbms_output.putline('l_num1=' || l_num1);
# end calc;
####### procedure - calc ##########################


# 인자로 받은 문자열을 특정 파일에서 찾아서 라인번호 출력하기
#!/bin/sh

# set parameter(keyword) to grep in log file
# if matched, get line number of log file and save result]

# usage
# findString.sh <keyword1> <keyword2> <keyword3> ... <keywordN>

# change log file
logfilename='SF_LONG_COLLECT_AMT_CHA.log'
let i=0
set -A result

# check each keyword
for str in $@ ; do
  # get line number of matching line in log file
  linenum=`grep -n $str $logfilename | cut -d: -f1`

  # if matched, save result
  if [ "#$linenum" != "#" ] ; then
    result[$i]="$logfilename[$str]:$linenum"
    let i=i+1
  fi
done

i=0
while [ $i -lt ${#result[@]} -1 ]
do
  # print result
  echo ${result[$i]}
  let i=i+1
done


# properties 파일 읽기
#!/bin/sh

confFile="./config.properties"
KEY_USERID="USERID"
KEY_PASSWD="PASSWD"
KEY_SERVER_IP="SERVER_IP"
KEY_SERVER_PORT="SERVER_PORT"

# check if file exists
if [ ! -f $confFile ]; then
  echo "$confFile : does not exist"
  exit 1
# check if can read
elif [ ! -r $confFile ]; then
  echo "$confFile : can not read"
  exit 2
fi

 exec 0<$confFile
 while read line
 do
   isComment=`echo $line | cut -c 1-1`

   if [ $isComment != "#" ]; then
     key=`echo $line | cut -d= -f1`

       if [ $key = $KEY_USERID ]; then
         VALUE_USERID=`echo $line | cut -d= -f2`
       elif [ $key = $KEY_PASSWD ]; then
         VALUE_PASSWD=`echo $line | cut -d= -f2`
       elif [ $key = $KEY_SERVER_IP ]; then
         VALUE_SERVER_IP=`echo $line | cut -d= -f2`
       elif [ $key = $KEY_SERVER_PORT ]; then
         VALUE_SERVER_PORT=`echo $line | cut -d= -f2`
       fi
   fi
 done

echo "$KEY_USERID=$VALUE_USERID"
echo "$KEY_PASSWD=$VALUE_PASSWD"
echo "$KEY_SERVER_IP=$VALUE_SERVER_IP"
echo "$KEY_SERVER_PORT=$VALUE_SERVER_PORT"

#!/bin/sh

confFile="./config.properties"
KEY_USERID="USERID"
KEY_PASSWD="PASSWD"
KEY_SERVER_IP="SERVER_IP"
KEY_SERVER_PORT="SERVER_PORT"

# check if file exists
if [ ! -f $confFile ]; then
  echo "$confFile : does not exist"
  exit 1
# check if can read
elif [ ! -r $confFile ]; then
  echo "$confFile : can not read"
  exit 2
fi

VALUE_USERID=`grep $KEY_USERID $confFile | cut -d= -f2`
VALUE_PASSWD=`grep $KEY_PASSWD $confFile | cut -d= -f2`
VALUE_SERVER_IP=`grep $KEY_SERVER_IP $confFile | cut -d= -f2`
VALUE_SERVER_PORT=`grep $KEY_SERVER_PORT $confFile | cut -d= -f2`

echo "$KEY_USERID=$VALUE_USERID"
echo "$KEY_PASSWD=$VALUE_PASSWD"
echo "$KEY_SERVER_IP=$VALUE_SERVER_IP"
echo "$KEY_SERVER_PORT=$VALUE_SERVER_PORT"
:
Posted by 뽀기