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

时间:2022-03-17 09:10:07

 报错现象:在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变量即可。