SHELL SCRIPT 에러 확인

h2ogid의 이미지

아래 형식의 SCRIPT 를 만드는데

에러가 나는 부분을 못찾겠습니다.

#!/bin/sh

#*
#****************EXPORT DATE******************************************
TODAY=`date +%Y%m%d`
TODAY_TIME=`date +%H`
YESTERDAY=`TZ=GMT+24 date +%Y%m%d`
HOST=`hostname`
#*********************************************************************

#*
#****************EXPORT DIR*******************************************
export HOME_DIR=/TEST_DIR/
export DATA_DIR=$HOME_DIR/DATA
export SEND_DIR=$HOME_DIR/SEND
#*********************************************************************

#*
#****************EXPORT CYCLE*****************************************
#1시간 주기로 전송 하므로 처음 전송은 01시, 마지막 전송은 익일 00시
#*********************************************************************

echo "START"

#***DATA DIR 로 이동
cd $DATA_DIR

#*** 일별로 1번째 실행 SCRIPT 인지 확인 후 전일자 처리
if [ $TODAY_TIME -eq 00 ];
then
ls -rtl ${YESTERDAY}deviceStat*.log | awk '{printf "%s\n",$9}' > $SEND_DIR/temp2.txt

#***temp1.txt,temp2.txt 를 비교하여 읽을 파일이 있는 지 확인
if diff -q $SEND_DIR/temp1.txt $SEND_DIR/temp2.txt &>/dev/null; then
echo "SAME FILE"
else
#***SEQ 는 SCRIPT 가 실행된 시간 이지만 00시는 24로함
SEQ=24

#***temp1.txt,temp2.txt 를 비교하여 전일자 마지막 전송 파일을 찾음
fgrep -vf $SEND_DIR/temp1.txt $SEND_DIR/temp2.txt >> $SEND_DIR/diff.txt

#***파일리스트를 읽어서 색인
LIST_FILE=`cat $SEND_DIR/diff.txt`
for LIST in $LIST_FILE
do
cat $DATA_DIR/$LIST | grep -E "aa|ab" >> SEND_DIR/$HOSTNAME_$YESTERDAY_REST_LOG_$SEQ.log
done

#***temp1 목록 갱신 후 기록을 위해 파일명 변경
cat $SEND_DIR/diff.txt >> $SEND_DIR/temp1.txt
mv $HOME_DIR/temp1.txt $SEND_DIR/$HOSTNAME_$YESTERDAY_REST_HIST.log

#***전송한 파일 백업
cd $SEND_DIR
mkdir ${YESTERDAY}
mv $SEND_DIR/$HOSTNAME_$YESTERDAY_REST* $SEND_DIR/${YESTERDAY}/

fi

else
#***TODAY 처음 전송이므로 temp1.txt 에 LIST 작성
if [ $TODAY_TIME -eq 01 ];
then
#***ls 시 마지막 파일은 제외하고 LIST 작성
FC=`ls -rtl ${TODAY}deviceStat*.log | wc | awk '{printf "%d\n",$1}'`
RFC=`expr $FC - 1`
ls -rtl ${TODAY}deviceStat*.log | head -n${RFC} | awk '{printf "%s\n",$9}' > $SEND_DIR/temp1.txt

#***SEQ 는 SCRIPT 가 실행된 시간
SEQ=$TODAY_TIME

#***파일리스트를 읽어서 색인
LIST_FILE=`cat $SEND_DIR/temp1.txt`
for LIST in $LIST_FILE
do
cat $DATA_DIR/$LIST | grep -E "aa|ab" >> SEND_DIR/$HOSTNAME_$YESTERDAY_REST_LOG_$SEQ.log
done

else

#***ls 시 마지막 파일은 제외하고 LIST 작성
FC=`ls -rtl ${TODAY}deviceStat*.log | wc | awk '{printf "%d\n",$1}'`
RFC=`expr $FC - 1`
ls -rtl ${TODAY}deviceStat*.log | head -n${RFC} | awk '{printf "%s\n",$9}' > $SEND_DIR/temp2.txt

#***temp1.txt,temp2.txt 를 비교하여 이전 마지막 전송 파일을 찾음
if diff -q $SEND_DIR/temp1.txt $SEND_DIR/temp2.txt &>/dev/null; then
echo "SAME FILE"
else
fgrep -vf $SEND_DIR/temp1.txt $SEND_DIR/temp2.txt >> $SEND_DIR/diff.txt

#***SEQ 는 SCRIPT 가 실행된 시간
SEQ=$TODAY_TIME`

#***파일리스트를 읽어서 색인
LIST_FILE=`cat $SEND_DIR/diff.txt`
for LIST in $LIST_FILE
do
cat $DATA_DIR/$LIST | grep -E "aa|ab" >> SEND_DIR/$HOSTNAME_$YESTERDAY_REST_LOG_$SEQ.log
done

#***temp1 목록 갱신
cat $SEND_DIR/diff.txt >> $SEND_DIR/temp1.txt

fi
fi
fi

echo "END"

exit 0

hernian의 이미지

#***SEQ 는 SCRIPT 가 실행된 시간
SEQ=`$TODAY_TIME`

h2ogid의 이미지

SEQ=$TODAY_TIME

` <- 요거 표시 안지움 ㅠㅠ

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.