当前位置:   article > 正文

mac 中定时任务执行时的环境不同于手动执行时的环境

mac 中定时任务执行时的环境不同于手动执行时的环境

env: node: No such file or directory

env: node: No such file or directory

的问题

本地执行 env获取 手动执行的环境

在脚本中 添加 env > /tmp/env.log

对比:

本地中的环境

  1. TERM_SESSION_ID=w0t0p0:B13A6A43-7378-415D-A34D-410B54F38998
  2. SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.9pNWdDeUfe/Listeners
  3. LC_TERMINAL_VERSION=3.4.22
  4. COLORFGBG=7;0
  5. ITERM_PROFILE=Default
  6. XPC_FLAGS=0x0
  7. LANG=zh_CN.UTF-8
  8. PWD=/Users/pengzhanliang/go/src/pop-develop-global-server
  9. SHELL=/bin/zsh
  10. __CFBundleIdentifier=com.googlecode.iterm2
  11. TERM_PROGRAM_VERSION=3.4.22
  12. TERM_PROGRAM=iTerm.app
  13. PATH=/var/www/91ke:/usr/local/opt/coreutils/libexec/gnubin:/usr/local/Cellar/openssl/1.0.2s/bin:/usr/local/Cellar/php/8.1.12/bin/sbin:/usr/local/Cellar/php/8.1.12/bin:/usr/local/opt/coreutils/libexec/gnubin:/Users/pengzhanliang/Library/Python/3.9/bin:/usr/local/opt/go@1.16/bin:/usr/local/opt/icu4c/sbin:/usr/local/opt/icu4c/bin:/bin:/usr/bin:/usr/local/bin:/usr/local/Cellar/redis@3.2/3.2.13/bin:/usr/local/Cellar/php@7.1/7.1.33/sbin:/usr/local/Cellar/php@7.1/7.1.33/bin:/libexec/gnubin:/var/www/91ke:/usr/local/opt/coreutils/libexec/gnubin:/usr/local/Cellar/openssl/1.0.2s/bin:/usr/local/Cellar/php/8.1.12/bin/sbin:/usr/local/Cellar/php/8.1.12/bin:/usr/local/opt/coreutils/libexec/gnubin:/Users/pengzhanliang/Library/Python/3.9/bin:/usr/local/opt/go@1.16/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/usr/local/go/bin:/Users/pengzhanliang/go/bin:/usr/local/Cellar/mongodb-community@3.2/3.2.22/bin:/Users/pengzhanliang/go/bin:/usr/local/Cellar/mongodb-community@3.2/3.2.22/bin
  14. LC_TERMINAL=iTerm2
  15. COLORTERM=truecolor
  16. COMMAND_MODE=unix2003
  17. TERM=xterm-256color
  18. HOME=/Users/pengzhanliang
  19. TMPDIR=/var/folders/pm/8qhqb_zn4bgg6hw9mv9thck80000gn/T/
  20. USER=pengzhanliang
  21. XPC_SERVICE_NAME=0
  22. LOGNAME=pengzhanliang
  23. ITERM_SESSION_ID=w0t0p0:B13A6A43-7378-415D-A34D-410B54F38998
  24. __CF_USER_TEXT_ENCODING=0x0:25:52
  25. SHLVL=1
  26. OLDPWD=/Users/pengzhanliang/go/src
  27. GO111MODULE=on
  28. GOPROXY=https://mirrors.tencent.com/go/
  29. GOPATH=/Users/pengzhanliang/go
  30. GOBIN=/Users/pengzhanliang/go/bin
  31. GOPRIVATE=gitlab.paquapp.com
  32. GONOPROXY=gitlab.paquapp.com
  33. GONOSUMDB=gitlab.paquapp.com
  34. LDFLAGS=-L/usr/local/Cellar/openssl/1.0.2s/lib

很多很多,两者相差很大,需要手动添加需要的环境

脚本中的环境

  1. SHELL=/bin/sh
  2. OLDPWD=/Users/pengzhanliang/go/src/runing
  3. USER=pengzhanliang
  4. PATH=/usr/bin:/bin
  5. PWD=/Users/pengzhanliang/go/src/runing
  6. HOME=/Users/pengzhanliang
  7. SHLVL=2
  8. LOGNAME=pengzhanliang
  9. _=/usr/bin/env

比如,我需要 node环境就添加:

export PATH="/usr/local/bin:$PATH"

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号