我目前正试图在PHP脚本中使用exec()执行一个命令,但时间延迟了。
我试过了:
exec('at now | fooCommand >> aLog.log 2>&1');
不工作并且:
exec('fooCommand >> aLog.log 2>&1 | at now');
两者都没有。但是:
exec('echo "fooCommand >> aLog.log 2>&1" | at now"');
有效,但似乎只启动echo命令,而不是所需的fooCommand。
有什么想法可以写这篇更正吗?
经过大量搜索,找到了解决方案:
exec('echo "fooCommand >> aLog.log 2>&1" | at now + 2 hours');
如果您要延迟脚本,我认为使用sleep而不是at会更有益(at只能使用分钟以上,没有秒)。
fooCommand是一个变量吗?如果是这样,请尝试中间的解决方案,但用双引号替换单引号。
exec("fooCommand >> aLog.log 2>&1 | at now");
在PHP中,当您将变量括在单引号中时,会忽略它们。