[MAC] Crontab ์˜ค๋ฅ˜ ์ •๋ฆฌ(Operation not permitted, Permission denied)

SHORTCUT

    ๋ฐ˜์‘ํ˜•
    ๐Ÿฅธ
    case1 ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‚˜์š”? ๊ทธ๋ ‡๋‹ค๋ฉด case2๊นŒ์ง€ ์ฒดํฌํ•˜์…”์„œ ์„ค์ •ํ•ด์ฃผ์…”์•ผ์ง€ ํฌ๋ก ํƒญ์ด ์ •์ƒ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค! :D

    case1) Permission denied ๋ฐœ์ƒ

    • ์›์ธ : ํ•ด๋‹น ํŒŒ์ผ์˜ ์‹คํ–‰ ๊ถŒํ•œ์ด ์—†๊ธฐ ๋•Œ๋ฌธ!
      • ์‚ฌ๋žŒ์ด ์•„๋‹Œ ์ปดํ“จํ„ฐ๊ฐ€ ํŒŒ์ผ์„ ์‹คํ–‰์‹œํ‚ค๋Š” ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์—, ํ•ด๋‹น ํŒŒ์ผ์— ๋Œ€ํ•œ ์‹คํ–‰ ๊ถŒํ•œ์„ ํ—ˆ๊ฐ€ํ•ด์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
    • ํ•ด๊ฒฐ : ํ„ฐ๋ฏธ๋„์—์„œ chmod +x {๊ฒฝ๋กœ/ํŒŒ์ผ.py} ์„ ์‹คํ–‰ํ•˜๊ธฐ
      • chmod +x ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜์—ฌ, ๊ถŒํ•œ์„ ๋ถ€์—ฌํ•˜๊ธฐ (ํ„ฐ๋ฏธ๋„์—์„œ ์‹คํ–‰ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค)
        # ํ•ด๊ฒฐ
        chmod +x /users/main.py
        
        # ์‹คํ–‰์‹œ, ๋ณ„๋„ ์‘๋‹ต์€ ์—†์Šต๋‹ˆ๋‹ค ^^;
      chmod +x {๊ฒฝ๋กœ/ํŒŒ์ผ} ์ปดํ“จํ„ฐ์—๊ฒŒ {๊ฒฝ๋กœ}์— ์žˆ๋Š” ํŒŒ์ผ ์ ‘๊ทผ ๊ถŒํ•œ์„ ๋ถ€์—ฌํ•˜๋Š” ๋ช…๋ น์–ด

    case2) Operation not permitted ๋ฐœ์ƒ

    • ์›์ธ : cron ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์ด disc์— ์ ‘๊ทผํ•˜๋Š” ๊ถŒํ•œ์„ ๋ถ€์—ฌํ•˜์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ!
    • ํ•ด๊ฒฐ : ์•„๋ž˜์˜ ๊ณผ์ •์„ ๋”ฐ๋ผ๊ฐ„๋‹ค.
      1. ๋งฅ๋ถ์˜ ์‹œ์Šคํ…œ ํ™˜๊ฒฝ์„ค์ • โ†’ ๋ณด์•ˆ ๋ฐ ๊ฐœ์ธ ์ •๋ณด ๋ณดํ˜ธ โ†’ ๊ฐœ์ธ ์ •๋ณด ๋ณดํ˜ธ ์„ ์—ฐ๋‹ค
      1. ์ขŒ์ธก ๋ฆฌ์ŠคํŠธ ์ค‘ ์ „์ฒด ๋””์Šคํฌ ์ ‘๊ทผ ๊ถŒํ•œ ์„ ์„ ํƒํ•œ ๋’ค, ์ขŒ์ธก ํ•˜๋‹จ ์ž๋ฌผ์‡ ๋ฅผ ๋ˆŒ๋Ÿฌ ๊ถŒํ•œ ๋ถ€์—ฌ๋ฅผ ์„ ํƒํ•œ๋‹ค.
      1. ์šฐ์ธก ๋ฆฌ์ŠคํŠธ ๋ฐ‘ + ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ, cron์„ ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.
      1. ์—ด๊ธฐ ์ฐฝ์ด ๋œจ๋ฉด, cmd + shift + G ๋ฅผ ๋ˆŒ๋Ÿฌ ๊ฒฝ๋กœ๋ฅผ ์•„๋ž˜๋กœ ์ด๋™ํ•ด์ฃผ์–ด ํฌ๋ก ์„ ์—ด์–ด์ค€๋‹ค. *๊ฒฝ๋กœ : /usr/sbin/cron
      1. ๋ฆฌ์ŠคํŠธ์— ์ •์ƒ์ ์œผ๋กœ ํฌ๋ก ์ด ๋“ฑ๋ก๋˜์—ˆ๋‹ค๋ฉด, ๋‹ค์‹œ ์ž๋ฌผ์‡ ๋ฅผ ๋ˆŒ๋Ÿฌ ์ž ๊ถˆ์ค€๋‹ค.
      1. ๋!

    case3) ํŒŒ์ด์ฌ ๋ชจ๋“ˆ์„ ์ฐพ์ง€ ๋ชปํ•˜๋Š” ๊ฒฝ์šฐ ModuleNotFoundError

    • ์—๋Ÿฌ ์ƒ์„ธ
      Traceback (most recent call last):
        File "/Users/.../main.py", line 2, in <module>
          from clients.SeleniumClient import SeleniumClient
        File "/Users/.../main.py", line 4, in <module>
          from webdriver_manager.chrome import ChromeDriverManager
      ModuleNotFoundError: No module named 'webdriver_manager'
    • ์ž์„ธํ•œ ์›์ธ์€ ๋ชจ๋ฅด๋‚˜, ํŒŒ์ด์ฌ ์‹คํ–‰ ํ™˜๊ฒฝ์ด ์ฐจ์ด๊ฐ€ ์žˆ์–ด ๋ฐœ์ƒํ•˜๋Š” ์˜ค๋ฅ˜๋ผ๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค.
      • ๋งฅ์—์„œ ํŒŒ์ด์ฌ ๊ฒ€์ƒ‰์‹œ, python3 python3.10 ๋“ฑ๋“ฑ ๋‹ค์–‘ํ•œ ํŒจํ‚ค์ง€๊ฐ€ ์„ค์น˜๋˜์–ด ์žˆ์—ˆ๋‹ค.
      • ์ €๋Š” ๋‹ค๋ฅธ ๊ธ€์„ ๋ณด๊ณ  /usr/local/bin/python3 ์„ ์ž…๋ ฅํ–ˆ๋Š”๋ฐ, ์ฐพ์•„๋ณด๋‹ˆ ํ•ด๋‹น ํŒŒ์ผ์€ python3.10 ์˜ ๋ฐ”๋กœ๊ฐ€๊ธฐ ์‚ฌ๋ณธ์ด์—ˆ์Šต๋‹ˆ๋‹ค.
      • ์‹ค์ œ ํŒŒ์ด์ฌ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ–ˆ๋˜ ํ™˜๊ฒฝ์€ python3 ์˜€๊ณ , ํ•ด๋‹น ์œ„์น˜๋ฅผ ํ„ฐ๋ฏธ๋„์—์„œ which ํ‚ค์›Œ๋“œ๋กœ ์กฐํšŒํ•ด๋ณธ ๊ฒฐ๊ณผ ๋‹ค๋ฅธ ๊ฒฝ๋กœ์˜€์Šต๋‹ˆ๋‹ค.
    • python3 ํ™˜๊ฒฝ์—์„œ ์‹คํ–‰์— ํ•„์š”ํ•œ ๋ชจ๋“ˆ๋“ค์„ ์„ค์น˜ํ–ˆ์—ˆ๋Š”๋ฐ, ๋‹ค๋ฅธ ํŒŒ์ด์ฌ ๋ฒ„์ ผ์œผ๋กœ ์‹คํ–‰ํ•˜๋‹ค ๋ณด๋‹ˆ ๋ชจ๋“ˆ์„ ์ฐพ์ง€ ๋ชปํ•˜๋Š” ๊ฒƒ์ด๋ผ ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.
    • ๋‹ค์‹œ ์ œ๋Œ€๋กœ๋œ ํ™˜๊ฒฝ์œผ๋กœ ๊ฒฝ๋กœ๋ฅผ ๋ฐ”๊พธ๋‹ˆ ์ •์ƒ ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค!
      # 3์˜ ๋ฐฐ์ˆ˜๋งˆ๋‹ค(3,6,9,12 ...) ์‹คํ–‰๋˜๋Š” ํฌ๋ก ํƒญ
      */3 * * * * /Users/jacob/opt/anaconda3/bin/python3 {๊ฒฝ๋กœ}/main.py

    ๋ฐ˜์‘ํ˜•

    ๋Œ“๊ธ€

    Designed by JB FACTORY