bash 스크립트에서 정규표현식으로 입력에 대해

prankenmk2의 이미지

안녕하세요.

현재 서버 관리용 스크립트를 만들고 있습니다.

대략적인 모양새는

./server_manage.sh "ls -alh" -h 서버명1 서버명2 서버명3

으로 입니다.

저렇게 입력하면 각 서버에 ls -alh 명령어를 실행해 결과값을 보여주는 스크립트 입니다.

여기서 더하고 싶은 것은

./server_manage.sh "ls -alh" -h 서버명[1-3]

으로 입력해도 동일한 효과를 내고 싶은걸 하고 싶은데요.. (번호만 다른 서버가 많습니다.)

일단 지금은 저렇게 입력시 당연하겠지만 "서버명[1-3]" 을 서버명으로 인식을 해서 서버를 못 찾는다는 메세지가 나타납니다.

정규표현식은 이미 존재하는 파일의 내용을 찾는 패턴으로만 사용해서 전혀 감이 잡히질 않네요.

위와 같이 사용하려면 어떻게 스크립트를 짜야할까요?

어떤 힌트라도 부탁드립니다!!

감사합니다!

bigeye의 이미지

항상 [1-3]형식이여야 하는지요..

다른 형식도 가능하다면 이런 방법도 가능할 듯 싶습니다.

./server_manage.sh "ls -alh" -h 서버명{1..3}

또는

./server_manage.sh "ls -alh" -h 서버명{1,2,3}

하면 자동으로

./server_manage.sh "ls -alh" -h 서버명1 서버명2 서버명3

효과가 나게 될 것입니다.

p.s. 또한 이런 형식의 작업을 쉽게 하기 위해서 이미 dist라는 오픈소스 프로젝트가 있답니다.

http://dev.naver.com/projects/dist

prankenmk2의 이미지

답변 감사합니다!

큰 도움 되었습니다!!

제가 아직 많이 부족하네요... ㅠ

혹시 [1-3]하고 {1..3} 의 차이가 뭔지 알 수 있을까요?

Prentice의 이미지

bash는 정규표현식을 모른다고 생각하시면 됩니다.

가만 보시면 ls *.txt 라고 치지 ls .*\.txt라고 치시지는 않으시잖아요.

댓글 달기

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