[완료]rsync --progress 옵션을 가진 배쉬스크립트에서...

illyf의 이미지

glibc기반으로 (로케일이 필요합니다)
20메가짜리 젠투입니다... 필수 유틸들만 포함되어있습니다.
스크립트는 ..배쉬스크립트이고... busybox가 아니라 ..
util-linux .. corelinux패키지들이 설치 되어있습니다.
필요하다면 ... 사이즈가 허락한다면 ... 작은 유틸들은
좀더 설치가 가능합니다.

-------/opt/bin/sysres---------------------------------
#!/bin/bash

status=/tmp/progress.out
parser=/opt/bin/rparser

(rsync --aih --progress --stats /source/ /target |$rparser > $status 2>> /tmp/rsync.err)&

exit 0
---------------------------------------------------------

------/opt/bin/rparser-----------------------------------
#!/bin/sed -f
#
# rsync --progress옵션출력에 ... 프로그레싱에 .. ^M이 붙어
# 추가가 되기 때문에 \r을 \n으로 변경하기 위해서...
#
/\r/ {
s/\r/\n/g
}
----------------------------------------------------------

-------/opt/bin/mprogress---------------------------------
#!/bin/bash

DIALOG=/usr/bin/dialog
status=/tmp/progress.out

(
# ^M부분을 없애지 않으면 ..tail -f에서
# 에러가 출력됩니다...
# 파싱없이 tail -c39하면 .. 원하는 부분을
# 얻을수 있지만.. 라인마다 출력되는
# 파일 명도 얻기 위해서...
# 이방식은 피하고 있습니다.
tail -f $status |while read line
do
# 작업을 마치고 ...rsync --stats출력부분이 나올때
# 빈라인이 들어오면 .. 마칩니다.
[[ -z $line ]] && kill $(pidof tail) && break
echo "XXX"
echo $line
echo "XXX"
done
) | DIALOG --gauge "testscript" 20 70 0

exit 0
----------------------------------------------------------

/opt/bin/sysres && /opt/bin/mprogress

실행을 하면...
rsync프로그래스가 실제로 ... 라인하나로 ...
96.26K 0% 131.10kB/s 0:00:00^M 96.26K 100% 131.10kB/s 0:00:00^M
이렇게 .. 들어오기때문에 ... 파싱을 해준다해도 ...
라인이 완전히 마쳐지기 까지는 ... /opt/bin/mprogress로 ... 들어오지 않습니다.
질문이 .. 좀.... 그래서 .. 이부분을 어떻게 처리해야할지...고민입니다.

표준출력에서는 .. tail -f를 써도 문제가 안되지만.. 이렇게
스크립트로 .. 처리할때 ..^M부분이 문제가 되는데 ...
어떻게 처리를 해야할지 모르겠네요...

illyf의 이미지

질문자체가 좀 ... 문제가 있는듯합니다...
여튼...

변경되는 파일에서... 라인을 읽어오고자 하는거였는데....
-------/opt/bin/sysres---------------------------------
#!/bin/bash

status=/tmp/progress.out

(rsync --aih --progress --stats /source/ /target $status 2>> /tmp/rsync.err)&

exit 0
---------------------------------------------------------
-------/opt/bin/mprogress---------------------------------
#!/bin/bash

DIALOG=/usr/bin/dialog
status=/tmp/progress.out
fmtout=/tmp/progress.fmt
parser=/opt/bin/rparser

(
while read line
$parser <$status >$fmtout
do
echo $line
done <$fmtout
) | DIALOG --gauge "testscript" 20 70 0

exit 0
----------------------------------------------------------
그저 ...read line을 해줘도 ... 계속 읽어 들이네요....
이런 ...

;-)

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.