336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
일을 하다보면,
날짜별, 시간별로 쌓이는 Log들을 특정 서버에
전송 해야 하는 경우가 생긴다.
이것을 일일이 사람이 하기는 무척 짜증이 나는 일이다.

그러다보니 인간이란게 본래 편한것을 찾게 된다고
어떻게 좀 편하게 알아서 하도록 할수 없을까? 고민을 많이 했었다.

그러다 찾은 방법이 Shell Scriptor와 ftp를 적절히 조합하여 이용하면 될 듯하여
시간 내어서 만들어 봤다.
역시 사람은 머리를 서야 몸이 편하다.

예제.. 
 #!/bin/sh
# MYHOME : 계정 디렉토리
MYHOME=/home/arhemian
# SBIN_DIR : 이 쉘스크립트가 저장된 디렉토리
SBIN_DIR=${MYHOME}/sbin
# LOG_DIR : 전송할 로그파일이 쌓이는 디렉토리
LOG_DIR=${MYHOME}/log/
# ftp_script_file : ftp를 편하기 쓰기 위해 사용할 명령을 저장한 스크립트 파일
ftp_script_file=${SBIN_DIR}/ftpscript.pcl

# USER, PASSWD : ftp로 접속할 시스템의 계정 및 패스워드
USER=arhemian
PASSWD=12345678
# TARGETIP, TARGETDIR : ftp로 접속할 시스템의 IP주소 및 접속후 파일을 전송할 디렉토리
TARGETIP=192.168.1.100
TARGETDIR=log

# CUR_DATE : 전송하는 현제 날짜를 YYYYMMDD 형태로 저장 (20081118) 
CUR_DATE=`date +%Y%m%d`
 
# 기존에 ftp_script_file이 존재하면 삭제
if [ -r $ftp_script_file ]
then
    rm -rf $ftp_script_file
fi

# ftp_script_file을 생성
# ftp_script_file의 내용은 ftp접속후 계정 패스워드를 입력 후
# 타겟 디렉토리에 오늘 날짜로 디렉토리를 생성 후 그곳에
# LOG파일을 전송하도록 되어 있음
cat > $ftp_script_file << FTPSCRIPT_EOF
user ${USER} ${PASSWD}
lcd ${LOG_DIR}
bin
prompt
cd ${TARGETDIR}
mkdir ${CUR_DATE}
cd ${CUR_DATE}
mput *.log
bye
FTPSCRIPT_EOF

# FTP 접속 및 전송 
echo "target system : ${USER}, ${TARGETIP}"
ftp -n ${TARGETIP} < ${ftp_script_file}

# 생성된 ftp_script_file 삭제
rm -rf $ftp_script_file

위의 예제를 crontab에 등록하여 쓰면 매 일정 시간 마다 알아서 척척척 ㅋㅋ
crontab 사용법은 생략하게다. 다른곳에 자세히 설명된 곳들을 찾아볼것!

사용을 할때는 상황에 맞게 수정을 하면 된다.
이 예제도 쓰고 있는 것에서 중요한 부분만 때어다가 만든거라.....
안맞는 부분이 있을수도 쿨럭!
사실 나는 crontab으로도 쓰지만 간 혹 필요에따라 
C코드(데몬프로그램 등)에 추가하여 일정 시간 때마다
scriptor를 동작하도록 쓰고있다. 

큰 단점이 있는데 (주의 요망)
타겟의 passwd가 공개가 된다는 점!!!! (C code에서 사용한다면 passwd 같은 경우는 
C 코드 내부에서 불러다 쓰면 되므로 문제가 안된다)
뭐 이정도야 몸이 편한것에 대한 대가(?)로 크게 신경 쓸 일은 아니라고 본다.


336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Linux Shell Scripting Tutorial v1.05r3
A Beginner's handbook

Copyright © 1999-2002 by Vivek G. Gite <vivek@nixcraft.com>

nixCraft Logo :: Next generation *nix services
(Formally know as vivek-tech.com)

Linux Shell Scripting Tutorial - A Beginner's handbook

Table of Contents

Chapter 1: Quick Introduction to Linux
What Linux is?
Who developed the Linux?
How to get Linux?
How to Install Linux
Where I can use Linux?
What Kernel Is?
What is Linux Shell?
How to use Shell
What is Shell Script ?
Why to Write Shell Script ?
More on Shell...
Chapter 2: Getting started with Shell Programming
How to write shell script
Variables in shell
How to define User defined variables (UDV)
Rules for Naming variable name (Both UDV and System Variable)
How to print or access value of UDV (User defined variables)
echo Command
Shell Arithmetic
More about Quotes
Exit Status
The read Statement
Wild cards (Filename Shorthand or meta Characters)
More commands on one command line
Command Line Processing
Why Command Line arguments required
Redirection of Standard output/input i.e. Input - Output redirection
Pipes
Filter
What is Processes
Why Process required
Linux Command(s) Related with Process
Chapter 3: Shells (bash) structured Language Constructs
Decision making in shell script ( i.e. if command)
test command or [ expr ]
if...else...fi
Nested ifs
Multilevel if-then-else
Loops in Shell Scripts
for loop
Nested for loop
while loop
The case Statement
How to de-bug the shell script?
Chapter 4: Advanced Shell Scripting Commands
/dev/null - to send unwanted output of program
Local and Global Shell variable (export command)
Conditional execution i.e. && and ||
I/O Redirection and file descriptors
Functions
User Interface and dialog utility-Part I
User Interface and dialog utility-Part II
Message Box (msgbox) using dialog utility
Confirmation Box (yesno box) using dialog utility
Input (inputbox) using dialog utility
User Interface using dialog Utility - Putting it all together
trap command
The shift Command
getopts command
Chapter 5: Essential Utilities for Power User
Preparing for Quick Tour of essential utilities
Selecting portion of a file using cut utility
Putting lines together using paste utility
The join utility
Translating range of characters using tr utility
Data manipulation using awk utility
sed utility - Editing file without using editor
Removing duplicate lines from text database file using uniq utility
Finding matching pattern using grep utility
Chapter 6: Learning expressions with ex
Getting started with ex
Printing text on-screen
Deleting lines
Coping lines
Searching the words
Find and Replace (Substituting regular expression)
Replacing word with confirmation from user
Finding words
Using range of characters in regular expressions
Using & as Special replacement character
Converting lowercase character to uppercase
Chapter 7: awk Revisited
Getting Starting with awk
Predefined variables of awk
Doing arithmetic with awk
User Defined variables in awk
Use of printf statement
Use of Format Specification Code
if condition in awk
Loops in awk
Real life examples in awk
awk miscellaneous
sed - Quick Introduction
Redirecting the output of sed command
How to write sed scripts?
More examples of sed
Chapter 8: Examples of Shell Scripts
Logic Development:
Shell script to print given numbers sum of all digit
Shell script to print contains of file from given line number to next given number of lines
Shell script to say Good morning/Afternoon/Evening as you log in to system
Shell script to find whether entered year is Leap or not
Sort the given five number in ascending order (use of array)
Command line (args) handling:
Adding 2 nos. suppiled as command line args
Calculating average of given numbers on command line args
Finding out biggest number from given three nos suppiled as command line args
Shell script to implement getopts statement.
Basic math Calculator (case statement)
Loops using while & for loop:
Print nos. as 5,4,3,2,1 using while loop
Printing the patterns using for loop.
Arithmetic in shell scripting:
Performing real number calculation in shell script
Converting decimal number to hexadecimal number
Calculating factorial of given number
File handling:
Shell script to determine whether given file exist or not.
Screen handling/echo command with escape sequence code:
Shell script to print "Hello World" message, in Bold, Blink effect, and in different colors like red, brown etc.
Background process implementation:
Digital clock using shell script
User interface and Functions in shell script:
Shell script to implements menu based system.
System Administration:
Getting more information about your working environment through shell script
Shell script to gathered useful system information such as CPU, disks, Ram and your environment etc.
Shell script to add DNS Entery to BIND Database with default Nameservers, Mail Servers (MX) and host
Integrating awk script with shell script:
Script to convert file names from UPPERCASE to lowercase file names or vice versa.
Chapter 9: Other Resources
Appendix - A : Linux File Server Tutorial (LFST) version b0.1 Rev. 2
Appendix - B : Linux Command Reference (LCR)
About the author
About this Document