리눅스 쉘 스크립트 질문입니다

sanghun214의 이미지

초급자 입니다

#!/bin/sh
ps -ef | grep srv | cut -b 1-80
A_COT=`ps -ef | grep srv | cut -b 1-80 | wc -l`
echo "Total :" ${A_COT}

이 스크립트를 만들었는데

위에 명령을 80초 마다 계속 보이기 위해

이 다음 문장으로

while 을 이용해 스크립트를 이어만들고 싶은데 어떻게 해야할까요

익명 사용자의 이미지

while(true)
do
date
-> 이부분 에 넣으시면 됩니다.
sleep 80
done

sanghun214의 이미지

감사합니다 !

여기서도 질문이 있는데

date를 쓰면 날짜가 나올줄 알았는데 아니던데

그 이유를 알 수 있을까요

익명 사용자의 이미지

date
2015. 01. 29. (목) 16:10:08 KST

혹시 어떻게 출력이 되는지 궁굼합니다.

sanghun214의 이미지


출력 내용으로는 제가 원하는 ps 값만 80초 마다 반복되서 나왓고

방금 써주신 date에 날짜 함수에 대해서는 출력되지 않았습니다.

date를 넣고 안넣고의 차이가 없었습니다.

감사합니다!!

Sdsf3qUr의 이미지

쉘에서 그냥 date 입력하면 결과가 어찌 나오나요?

익명 사용자의 이미지

A_COT=`ps -ef | grep srv | cut -b 1-80 | wc -l`

while(true)
do
date
ps -ef | grep srv | cut -b 1-80
echo "Total :" ${A_COT}
sleep 80
done

결과값

./test.sh
2015. 01. 29. (목) 17:01:30 KST
root 5791 5782 0 17:01 pts/0 00:00:00 grep srv
Total : 1

sanghun214의 이미지

#!/bin/sh
while(true)
do
ps -ef | grep srv | cut -b 1-80
A_COT=`ps -ef | grep srv | cut -b 1-80 | wc -l`
echo "Total :" ${A_COT}
sleep 80
done

이렇게 했고요 다시 한번 확인해 보니 date 를 넣고 안넣고를 차이를 확인했습니다.

제가 너무 결과값을 겉보기로 본거 같습니다

date는 Fri Jan 30 09:15:43 KST 2015 형식으로 똑같이 나왔습니다.

도움주셔서 감사합니다

Sdsf3qUr의 이미지

watch라는 명령어가 있습니다. 어떤 환경이신지 모르겠지만 아마 설치 되어 있을 겁니다.

watch 명령어

이렇게 하시면 일정 시간 간격으로 명령어를 실행해서 그 결과를 보여 줍니다. 출력 결과의 전 후를 비교해서 차이점을 보여 준다던지 소리를 내 준다던지 하는 기능이 있습니다.

sanghun214의 이미지

오 한번 man 페이지 보고 확인해 보겠습니다
감사합니다

댓글 달기

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