crontab 에서 user 인식

amicus의 이미지

crontab으로 shell script를 실행시켜 apache와 tomcat을 restart 하려고 합니다. shell script에는 apache 와 tomcat 재실행하게 되어 있습니다.

apache는 root권한으로 설치되어 있고, tomcat은 일반유저로 설치되어 있습니다.( 왜 이렇게 설치했는지 이해 못하겠음. 열라 짜증남)

근데 crontab으로 shell을 실행시키면 apache만 실행됩니다.
물론 shell script를 직접실행하면 둘다 잘 실행 되져...

root 권한으로 crontab을 설정하면 그 shell이 root권한으로 실행되는거 아닌가요?
그리고 그 shell 안에 있는 다른 shell은 ( 일반유저권한) 어떻게 실행되는 건가요?

만약 user 문제라면 환경설정을 똑같이 하라고 하는데... PATH설정만 똑같이 하면 되나요?

dangsan49의 이미지

cron 실행이 실패하게 되면 로그가 남거나,
아님 사용자에게 메일이 날라오지 않나요?
그걸 보면 tomcat이 왜 실행이 안됐는지 알수있을
것입니다.
근데 apache는 root권한이 필요한 것이면
root의 crontab에
tomcat의 경우는 일반유저이므로
그 해당유저에 맞는 crontab에 설정해주면 되지 않나요?

그럴경우 아마 환경 문제(path설정)때문에 절대path로 적었던 기억이 남니다만...^^

VENI, VIDI, VICI - Caesar, Gaius Julius -

amicus의 이미지

crontab에서는 기존에 잡혀 있는 환경설정을 거의 무시하는 듯 합니다.

PATH 가 /usr/bin/bin 이렇게 밖에 잡혀 있지 않더군요..
그래서 톰캣 같은 경우, java 명령어가 필요한데..PATH가 잡혀 있지 않아
인식을 못한것 같습니다.

PATH를 export 시켜 주니까 정상적으로 작동하는 군요....

머 다 아시겠지만..저는 이것 때문에 고생 많이 했습니다..
코드 라인수도 겨우 20라인 안넘어가는 간단한 소스인데도 불구하고...고생했져.

혹시 리눅스를 처음 접하시는 분이 이글을 읽게 되면 도움이 되라고..허접하게나마 경험담을 올려 드립니다...

krisna의 이미지

아마도 보안 문제로 환경변수를 거의 새로 세팅하는 거로 알고 있습니다.
man 5 crontab 해보세요.

Quote:

.....
Several environment variables are set up automatically by the cron(8)
daemon. SHELL is set to /bin/sh, and LOGNAME and HOME are set from the
/etc/passwd line of the crontab’s owner. PATH is set to
"/usr/bin:/bin". HOME, SHELL, and PATH may be overridden by settings
in the crontab; LOGNAME may not.
.....

이렇게 나와 있군요

amicus의 이미지

답변 달아주셔서 감사합니다..

리눅스를 처음 접해보는거라 허접한게 많네요..
그냥 에러로그 보는 법이라도 알았더라면, 쉽게 알았을 텐데...

첫번째 답글 달아주신분 덕분에 PATH설정다시 해서 성공했구요..
두번째 답글 달아주신분 덕분에... 개념 잡았습니다..

spec이나 도움말을 자주 보는 습관을 들여야 하는데....아직 허접한지라...

댓글 달기

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