Bash 在工作而不是 运行 - 数组

Bash at job not running - Array

我已经构建了一个 bash 脚本,当从命令行执行时 运行 没问题,但当 运行 作为批处理作业(使用 at)时它不起作用。首先我认为是因为环境,但在调试时我认为我需要创建的数组有问题。当创建来自命令行日志的 运行 并且其内容是我所期望的但是当 运行 with at any log 被创建时。知道是什么导致了这个问题吗?

一段简短的脚本,我想它不是 运行ning 在下面

#!/bin/bash

fsol=`date +%Y%m%d`

for dia
  in 0 1 2 
do

  var=$(date -d "$fsol +$dia days" +'%Y-%m-%d')

  orto=`awk -v j=$var 'BEGIN { FS=","}  == j { print }' hora-sol.dat`

  h_orto=${orto:0:2}
  m_orto=${orto:2:2}

  a_orto+=($h_orto $m_orto)

echo "dia $dia" $var $h_orto $m_orto  >> log1.txt

done

echo ${a_orto[@]} >> log2.txt

hora-sol.dat

中的数据
32,2016-02-01,0711,1216,1722,10.1885659530428
33,2016-02-02,0710,1216,1723,10.2235441870822
34,2016-02-03,0709,1216,1724,10.2589836910036
35,2016-02-04,0708,1216,1725,10.2948670333624
36,2016-02-05,0707,1216,1727,10.3311771153741
37,2016-02-06,0706,1217,1728,10.3678971831004
38,2016-02-07,0705,1217,1729,10.4050108377139
39,2016-02-08,0704,1217,1730,10.4425020444393
40,2016-02-09,0703,1217,1731,10.4803551390436
41,2016-02-10,0701,1217,1733,10.5185548339287
42,2016-02-11,0700,1217,1734,10.5570862213108
43,2016-02-12,0659,1217,1735,10.5959347763989
44,2016-02-13,0658,1217,1736,10.6350863580571
45,2016-02-14,0657,1217,1737,10.6745272092687
46,2016-02-15,0655,1217,1738,10.7142439549499
47,2016-02-16,0654,1217,1740,10.7542236006922
48,2016-02-17,0653,1217,1741,10.7944535282585
49,2016-02-18,0652,1216,1742,10.8349214920733
50,2016-02-19,0650,1216,1743,10.8756156133281
51,2016-02-20,0649,1216,1744,10.9165243743526
52,2016-02-21,0648,1216,1745,10.9576366115941
53,2016-02-22,0646,1216,1746,10.9989415078031
54,2016-02-23,0645,1216,1747,11.0404285846154
55,2016-02-24,0644,1216,1749,11.0820876932144
56,2016-02-25,0642,1216,1750,11.123909005324
57,2016-02-26,0641,1215,1751,11.1658830035395
58,2016-02-27,0639,1215,1752,11.2080004711946
59,2016-02-28,0638,1215,1753,11.2502524821626
60,2016-02-29,0636,1215,1754,11.2926303895977

运行 手动生成:

# cat log.txt 
dia 0 2016-02-12 0659 1217 1735
dia 1 2016-02-13 0658 1217 1736
dia 2 2016-02-14 0657 1217 1737
06
59
06
58
06
57

安排时间:

# echo "/tmp/horasol/script.sh" | at now +1 minute 
warning: commands will be executed using /bin/sh
job 1 at Fri Feb 12 12:11:00 2016

生成的完全一样:

# cat log.txt 
dia 0 2016-02-12 0659 1217 1735
dia 1 2016-02-13 0658 1217 1736
dia 2 2016-02-14 0657 1217 1737
06
59
06
58
06
57

请注意,通知 'at' 使用 /bin/sh 的警告: 警告:命令将使用 /bin/sh

执行

告诉我们您如何得出结论“在 运行 作为批处理作业(使用 at) 时不起作用”

告诉我们更多关于你的“调试时”的时刻。

也许我在这里使用与您不同的过程进行复制。由于这种差异,它对我有用。