报错现象:在shell下执行node没有任何问题,但crontab自动运行就会报错。

 crontab 执行脚本,报错/home/scripts/eyeMonitor.sh: line 8: node: command not found

原因:node的安装路径:/root/.nvm/versions/node/v6.7.0/bin/node

crontab 执行脚本,报错/home/scripts/eyeMonitor.sh: line 8: node: command not found

Shell环境PATH变量中已配置,因此在shell下可以执行。

但要知道,我们这是在crontab下定时运行,因此需要检查crontab的环境变量。

[root@WEB4 node]# vim /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed

从上面的检查结果可以看出,node的path没有配置,此处增加下node的安装路径到PATH变量即可。 

 

相关文章:

  • 2021-07-21
  • 2021-05-02
  • 2021-08-27
  • 2022-12-23
  • 2021-05-25
  • 2021-09-16
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-23
  • 2021-04-29
  • 2021-09-10
相关资源
相似解决方案