前端之家收集整理的这篇文章主要介绍了
[CentOS] 解决 crontab 无法读取环境变量的问题,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
1. 问题描述
一段数据处理的 shell 程序,在 shell 中手动运行,可以正确执行。但是,把它放在 crontab 列表里,就会报错,提示 "matlab: command not found."。
AutoRefreshData.sh 的部分内容如下:
@H_
301_8@
[She@She ~]$ cat /home/She/data/AutoRefreshData.sh
#!/bin/bash
...
MatlabFile='/mnt/L/Data/main4mat.m'
chmod +x ${MatlabFile}
matlab -nodesktop -nosplash -nojvm < ${MatlabFile} 1>running.log 2>running.err &
[She@She ~]$ /home/She/data/AutoRefreshData.sh
[She@She ~]$ cat ~/running.log
< M A T L A B (R) >
Copyright 1984-2015 The MathWorks,Inc.
R2015b (8.6.0.267246) 64-bit (glnxa64)
August 20,2015
For online documentation,see http://www.mathworks.com/support
For product information,visit www.mathworks.com.
>> >> >> >> >> >> >> /mnt/L/Data/matFile/jpl16228.mat
>>
[She@She ~]$ cat ~/running.err
[She@She ~]$
[She@She ~]$ crontab -l
# part 2: refresh She data from FTP
08 12 * * * /home/She/data/AutoRefreshData.sh > /dev/null 2>&1
[She@She ~]$ cat ~/running.log
[She@She ~]$ cat ~/running.err
/home/She/data/AutoRefreshData.sh: line 111: matlab: command not found
#!/bin/sh
. /etc/profile
. ~/.bash_profile