bash - 在 Bash 中将 Matlab (Linux) 作为 Cron 作业运行的输出在电子邮件中包含许多“>>”
问题描述
我在 Linux(RedHat Enterprise Linux RHEL 7.6,64 位)上运行 Matlab 脚本作为 cron 作业。我不是那台机器的管理员,因此,我用它crontab -e
来安排工作。Matlab的安装版本是2018b。我在执行时收到的电子邮件包括>>
开头和结尾的几封邮件,我觉得这有点烦人。
这里是电子邮件的示例:
MATLAB is selecting SOFTWARE OPENGL rendering.
< M A T L A B (R) >
Copyright 1984-2018 The MathWorks, Inc.
R2018b (9.5.0.944444) 64-bit (glnxa64)
August 28, 2018
To get started, type doc.
For product information, visit www.mathworks.com.
>> >> >> >>
Matlab started: 2020-07-31 21:50:26.
>> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >>
Going to update from 2015-01-01 00:00:00 UTC to 2015-12-31 23:00:00 UTC.
[...]
>> Matlab closes: 2020-07-31 23:26:41.
>>
Matlab 脚本开头的相应行如下所示:
close all
clearvars
% profile on % to check performance
fprintf('\nMatlab started: %s.\n', char(datetime()))
%% Database user parameters
% connects always to the soecified database on "localhost"
DB_conn_name = 'abc';
DB_username = 'def';
DB_password = 'ghi';
% Add path and subfolders
if isunix
addpath(genpath('/project/abc'));
elseif ispc
addpath(genpath('C:\Branches\abc'));
end
% Change working folder
if isunix
cd /project/abc
elseif ispc
cd C:\Branches\abc
end
% Add database driver to path
javaaddpath JDBC_driver/mysql-connector-java.jar % Forward slashes within Matlab work even on Windows
% Set default datetime format
datetime.setDefaultFormats('default','yyyy-MM-dd HH:mm:ss')
%% Begin and end of update period
% now_UTC = datetime('now','TimeZone','UTC');
% time_2 = datetime(now_UTC.Year, now_UTC.Month, now_UTC.Day-1, 22, 0, 0); % Set the end time not too late, otherwise, some data might not yet be available for some areas leading to ugly "dips" in Power BI.
% During each update, we update e.g. the past 30 days
% datetime_month_delay = time_1 - days(30);
% Override automatic dates obtained below, for testing purposes
% time_1 = datetime(2020,1,1,0,0,0);
% time_2 = datetime(2020,2,1,23,0,0);
% Updating several years, one at a time
for iYear = 2015:2019
time_1 = datetime(iYear,1,1,0,0,0);
time_2 = datetime(iYear,12,31,23,0,0);
fprintf(['\nGoing to update from ',char(time_1),' UTC to ',char(time_2),' UTC. \n'])
[...]
看起来for
循环外的每一行都会产生一个空行,因此>>
在输出中会出现这样的提示。最后也可见(此处不包括)。
crontab -e
如下所示:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=<my email address>
HOME=/project/abc
HTTP_PROXY=<proxy address>:8086
HTTPS_PROXY=<proxy address>:8086
# Run script regularly: minute hour day month dayofweek command
# No linebreaks allowed
15 2 * * * ~/script.sh
shell 脚本script.sh
如下所示:
#!/bin/bash
/prog/matlab2018b/bin/matlab -nodesktop < ~/git-repos/abc/matlabscript.m
有谁知道我需要改变什么来摆脱这些>>
?那很好啊!提前致谢!
解决方案
推荐阅读
- python - IndexError:列表索引超出范围,动画精灵,角色移动
- javascript - 有没有比使用 isTrusted 注册对 Javascript 动画的点击更好的方法?
- mysql - 从 DataGrid 更新时图表重复系列
- apache - Apache Hbase - 获取大行非常慢
- netsuite - 当项目履行日期与发票日期不同时突出显示结果
- r - 有效过滤没有单一唯一值的数据
- python - 如果 if 语句未在循环内激活,是否有条件运行?
- python - 如何在 pandas 中获得等效的 SQL SELF JOIN?
- python - 根据另一个列表的索引将列表拆分为块
- sql - 表子集上的自 LEFT JOIN