쉘 스크립트에서 sqlplus 스크립트를 이용하기

쉘 스크립트안에서 sqlplus 스크립트를 실행하는 방법에 대한 팁이다.
이 팁은 데이터베이스 값을 쉘 변수로 전달하는 방법과 쉘 스크립트를
좀더 다이나믹하게 만들어주는 예이다. 어떤 사람들에게는 기초적인
것일수 있으나 다른 사람들에게 도움이 되기 바란다. 문법은 다음과 같다:

#!/bin/sh
dummyvar=`sqlplus -s username/password  <<end
set pagesize 0 feedback off ver off heading off echo off
select  sysdate from dual;
exit;
end`
echo "system date is " $dummyvar
#end of shell script

이 예제는 오라클에서 시스템의 날짜를 받아오는 것이지만 여러분들이
데이터베이스에서 원하는 정보를 가져와 쉘 변수에 넣도록 select
스크립트를 확장하는 방법에 대한 아이디어를 얻을 수 있다.

@@@@@@@@@@@@@@@@@@@[ 원문 ]@@@@@@@@@@@@@@@@@@@
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                             UNIX GURU UNIVERSE
                                UNIX HOT TIP

                       Unix Tip 2578 - January 23, 2007

                   http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

SHELL SCRIPTING A SQLPLUS SCRIPT

Here is a tip on how to run sqlplus scripts within a shell script.
It is an example of how to pass database values into shell variables
and to make shell scripts more dynamic. This maybe elementary to some
folks but hope it helps others.....Here is the syntax:

#!/bin/sh
dummyvar=`sqlplus -s username/password  <<end
set pagesize 0 feedback off ver off heading off echo off
select  sysdate from dual;
exit;
end`
echo "system date is " $dummyvar
#end of shell script

This will retrieve the system date from Oracle but you get the idea
that you can expand the select script to get whatever you want from
the database and place it in a shell variable where you can make
decisions on it.

반응형
Posted by She쥐포s

2007. 11. 3. 21:58 Unix

fuser로 사용자 보기

fuser로 사용자 보기

System V 계열에서는 누가 특정 파일 시스템을 사용하고 있는지 보기 위해
다음의 명령을 사용할 수 있다:

fuser <파일 시스템>

예를 들어, /cdrom 디렉토리에 access 하고 있는 사람을 보려면:

fuser /cdrom

이 명령은 파일 시스템을 unmount 하고자 할 경우 사용중이어서 unmount가
불가능 할 경우에 유용하다.

@@@@@@@@@@@@@@@@@@@[ 원문 ]@@@@@@@@@@@@@@@@@@@

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                             UNIX GURU UNIVERSE
                                UNIX HOT TIP

                       Unix Tip 2577 - January 22, 2007

                   http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

I SEE YOU WITH FUSER

In System V, you can use the following command to see who is accessing
a particular file system:

fuser <file system>

For example, to see who is accessing the /cdrom directory:

fuser /cdrom

This command is useful if you wish to unmount a file system but the system
is unable to do so because it is being used.

반응형
Posted by She쥐포s

시스템 전반적인 경로 설정

- 플랫폼에 구애받지 않는 시스템 관리 팁

만일 모든 사용자에게 적용할 시스템 경로를 설정하고 싶다면,
사용자들이 어떤 쉘을 사용하던지 다음 파일을 편집하라:

Solaris :  /etc/default/login
HP-UX  :  /etc/PATH
AIX        : /etc/environment

@@@@@@@@@@@@@@@@@@@[ 원문 ]@@@@@@@@@@@@@@@@@@@
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                             UNIX GURU UNIVERSE
                                UNIX HOT TIP

                       Unix Tip 2576 - January 21, 2007

                   
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

GLOBAL SYSTEM PATH SETTINGS

Cross-Platform System Administration Tip

If you want to set a system path that will apply to all users,
regardless of which shell they use, edit the following file:

For Solaris: /etc/default/login
For HP-UX:   /etc/PATH
For AIX: /etc/environment

반응형
Posted by She쥐포s

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                             UNIX GURU UNIVERSE
                                UNIX HOT TIP

                       Unix Tip 2569 - January 14, 2007

                   http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

AWK QUICK COLUMNS

커맨드라인에서 awk를 사용하는 대부분의 시간에 여러분들은 다음과
같은 단순한 작업을 할 것이다.

ps -ef | grep netscape | awk '{ print $2 }'

타이핑을 덜하기 위하여, 하나 또는 그 이상의 행의 출력만을 위해 awk를
사용하려 한다면 이 스크립트를 사용하라.

------------------- 자르는 곳 ---------------------------
#!/bin/ksh
# awkc - 하나 또는 그 이상의 행을 출력

p=\$$( echo $1 | sed 's/,/,\$/g' )
shift
eval "awk '{ print $p }'" $*

# eof
------------------- 자르는 곳 ---------------------------

이제 다음과 같이 사용할 수 있다:

ps -ef | awkc 2,1

또는

awkc 1,2,3 /var/adm/messages*

@@@@@@@@@@@@@@@@@@@[ 원문 ]@@@@@@@@@@@@@@@@@@@

AWK QUICK COLUMNS

Most of the time when you use awk from the command line,
you're doing something simple like this:

ps -ef | grep netscape | awk '{print $2}'

To save typing, use this script when you only want to
use awk to print out one or more columns:

------------------- CUT HERE ---------------------------
#!/bin/ksh
# awkc - print out one or more columns

p=\$$( echo $1 | sed 's/,/,\$/g' )
shift
eval "awk '{ print $p }'" $*

# eof
------------------- CUT HERE ---------------------------

Now you can do things like:

ps -ef | awkc 2,1

or

awkc 1,2,3 /var/adm/messages*

반응형
Posted by She쥐포s

○ 다음은 cron 작업을 하면서 가장 법하기 쉬운 실수 중 하나이다.

- 쉘에서 직접 작업할 경우엔 이상없이 실행이 되지만
- cron을 통해 작업을 하게 되면 정상적으로 실행이 되지 않는 경우이다.

※ 이런 경우엔 쉘의 Profile을 인식을 하지 못한 경우인데 해결책으로는

1. 모든 명령에 전체경로를 적어주거나
2. 스크립트의 시작시에 .profile을 불러들이는 것이다.
    . $HOME/.profile 또는 source $HOME/.profile

※ Shell의 종류에 따라 .bash_profile이 될 수도 있다.

반응형
Posted by She쥐포s

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-­=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-­=-=-=-=-=
                             UNIX GURU UNIVERSE
                                UNIX HOT TIP

                       Unix Tip 2472 - October  8, 2006

                   http://www.ugu.com/sui/ugu­/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-­=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-­=-=-=-=-=

조건적으로 core 파일 지우기

조건적으로 core 파일을 찾아서 지우기 위해서는:

프롬프트> find ~ -name core -exec file {} \; -exec rm -i {} \;

file 명령어는 어떤 실행 파일이 core 파일의 원인인지 보여주고 rm의 -i 옵션은
파일을 지울것인지 말것인지를 선택할 수 있게 해줄 것이다.

################# 예제 #################
프롬프트>  find ~ -name core -exec file {} \; -exec rm -i {} \;
/my/home/core: ELF 32-bit LSB core file of 'netscape-commun'
(signal 3), Intel 8
rm: remove `/my/home/core'? y

@@@@@@@@@@@@@@@@@@@@[ 원문 ]@@@@@@@@@@@@@@@@@@@@

REMOVING CORES CONDITIONALLY

To find and remove core files
conditionally:

PROMPT> find ~ -name core -exec file {} \; -exec rm -i {} \;

The File will show which
executable the core file is
for and the -i option to rm
will allow you to choose
weather to delete it or not.

################# EXAMPLE ##############################­#
PROMPT>  find ~ -name core -exec file {} \; -exec rm -i {} \;
/my/home/core: ELF 32-bit LSB core file of 'netscape-commun'
(signal 3), Intel 8
rm: remove `/my/home/core'? y

반응형
Posted by She쥐포s

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                             UNIX GURU UNIVERSE
                                UNIX HOT TIP

                       Unix Tip 2444 - September 10, 2006

                   http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

리눅스에서의 최대 파일 갯수

프로세스 하나가 동시에 open할 수 있는 최대 파일 갯수는 다음의 명령을

사용하여 알아볼 수 있다.

getconf OPEN_MAX


@@@@@@@@@@@@@@@@@@@@[ 원문 ]@@@@@@@@@@@@@@@@@@@@

MAX FILES UNDER LINUX

Maximum number of files
that one process can
have open at one time can
be find out by using:

getconf OPEN_MAX

반응형
Posted by She쥐포s

---------------- Start of Script ----------------
#!/bin/sh

CUR_DATE=`date +%Y%m%d`

mkdir "$CUR_DATE"
---------------- End of Script ----------------
1. date 명령의 옵션을 이용해 현재의 날짜를 구하여
2. CUR_DATE라는 변수에 저장
3. CUR_DATE라는 이름으로 디렉토리 생성

※ 위의 내용을 응용하여 독립적인 스크립트로서가 아니고 다른 스크립트와
    함께 사용하면 더욱 유용할 수 있다.(예 : 백업을 날짜별로 받을 경우.. 등)

반응형
Posted by She쥐포s

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-­=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-­=-=-=-=-=
                             UNIX GURU UNIVERSE
                                UNIX HOT TIP

                       Unix Tip 2416 - August 13, 2006

                   http://www.ugu.com/sui/ugu­/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-­=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-­=-=-=-=-=

다음 이용할 수 있는 UID?

시스템상에서 다음 사용가능한 UID를 찾아내는 한가지 방법을 소개한다.

이 방법은 패스워드 파일과 그룹파일을 동시에 받아 다음 사용가능한 UID를 찾아
화면에 나타내준다.

#!/bin/bash
awk -F":" '{ print $3 }' /etc/passwd > number_list
awk -F":" '{ print $3 }' /etc/group >> number_list
A=` sort -g number_list | tail -1`
A=`expr $A + 1`
echo "New Available UID is $A"

※ 譯者 註 :
        - 괄호부분은 생략함.
        - sort -g : 숫자 정렬
        - awk -F":" '{ print $3 }' /etc/passwd > number_list
           :를 구분자로 하여 /etc/passwd 파일에서 3번째 필드를 number_list 파일에 저장한다.

@@@@@@@@@@@@@@@@@@@@[ 원문 ]@@@@@@@@@@@@@@@@@@@@

THE NEXT UID

Here is one way to find out the
next available UID on a system.

It takes both the password and
group files and finds the next
available UID and displays it.

(No cats were harmed in the making
of this script)

#!/bin/bash
awk -F":" '{ print $3 }' /etc/passwd > number_list
awk -F":" '{ print $3 }' /etc/group >> number_list
A=` sort -g number_list | tail -1`
A=`expr $A + 1`
echo "New Available UID is $A"

반응형
Posted by She쥐포s

2007. 11. 3. 21:40 Unix

make 과정 log 남기기

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                             UNIX GURU UNIVERSE
                                UNIX HOT TIP

                       Unix Tip 2414 - August 11, 2006

                   http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

make 과정 log남기기

make작업 또는 컴파일 작업 또는 패키지 빌드 과정의 로그를 보존하기
위해서는 다음과 같이 할 수 있다.

$ make bzImage 2>&1|tee build.log

또 다른 로그를 파일에 추가하려면 다음과 같이 하라.

$ make modules 2>&1|tee -a build.log

@@@@@@@@@@@@@@@@@@@@[ 원문 ]@@@@@@@@@@@@@@@@@@@@

LOGGING MAKES

To keep the log of make task or
compilation session or build
package process, you may do:

$ make bzImage 2>&1|tee build.log

To append further log to a file,
continue with:

$ make modules 2>&1|tee -a build.log

반응형
Posted by She쥐포s

블로그 이미지
She쥐포s
Yesterday
Today
Total

달력

 « |  » 2024.5
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 31

최근에 올라온 글

최근에 달린 댓글

글 보관함