作业未运行时Bash - 数组

时间:2016-02-12 11:51:44

标签: arrays bash batch-processing

我已经构建了一个bash脚本,该命令在从命令行执行时运行正常,但在作为批处理作业运行时(使用at)不起作用。首先,我认为由于环境,但在调试时我认为我需要创建的数组存在问题。从命令行运行时,会创建日志并且其内容是我所期望的,但是在创建任何日志时运行。是什么导致了这个问题?

我认为它没有运行的代码片段的短脚本在

之下
#!/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=","} $2 == j { print $3}' 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

1 个答案:

答案 0 :(得分:1)

手动运行,生成:

# 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:

进行调度
# 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

请注意,warninig通知'at'use / bin / sh: 警告:将使用/ bin / sh

执行命令

告诉我们您如何得出结论“在作为批处理作业运行时无效

告诉我们有关“调试时”时刻的更多信息。

也许我正在使用与你不同的过程来复制。由于这种差异,它对我有用。