Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crontab 执行 shell 脚本报错:node: command not found #156

Open
lovelmh13 opened this issue Jul 26, 2021 · 0 comments
Open

crontab 执行 shell 脚本报错:node: command not found #156

lovelmh13 opened this issue Jul 26, 2021 · 0 comments

Comments

@lovelmh13
Copy link
Owner

场景:

使用 crontab 定时任务执行 shell 中的 node 命令,mail 发送信息,发现报错:node: command not found。但是直接执行 shell 运行 node 没有问题。
代码如下:

#!/usr/bin/env bash
 
node /home/work/jarvis-service/shell/sendMobDailyMessage.js

查找问题:

检查发现安装了 nvm 来管理 node,通过查看环境变量,发现 node 的环境变量在 nvm 中。尝试使用 nvm 中的 node 路径来执行。成功解决。

代码如下:

#!/usr/bin/env bash
 
~/.nvm/versions/node/v14.14.0/bin/node /home/work/jarvis-service/shell/sendMobDailyMessage.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant