1


我正在构建一个天气数据采集系统。我想做的一件事是为每 15 分钟到达的卫星数据制作动画。事实上,我已经设计了一个脚本(animate名为 从终端手动运行时运行良好。

不幸的是,当从我的(如我的用户,而不是 root)crontab 运行时,不能这样说。

下面是我提到的 cron 作业:

1,16,31,46 * * * * /home/daniella/bin/anim_all > /home/daniella/logs/anim_all.log 2>&1

anim_all只需为每个不同的数据产品调用 animate :

#!/bin/bash
set -x
cd /home/daniella/data/imager

rm -rf HRIT_MSG3_*.avi

animate HRIT_MSG3_CTT
animate HRIT_MSG3_IR108
animate HRIT_MSG3_VIS006
animate HRIT_MSG3_WV062

并且动画本身调用ffmpeg.

#!/bin/bash

set -x
cd /home/daniella/data/imager
product=$1
hl="$product.8hl"

declare -i i=0
for file in $(cat $hl); do
    link=$(printf "images%02d.png" $i)
    ln -sf $file $link
    i=$((i+1))
    echo $i
done

ffmpeg -sameq -r 15 -i images%02d.png $product.avi
rm -rf images*.png

为了清楚起见,.8hl 文件只是一个引用最后 8 小时数据的 PNG 文件路径列表。由于每 15 分钟有一个新数据,因此这是一个 32 行的文本文件。最后,这是检查 anim_all.log(在 crontab 中引用)文件时返回的错误。

+ animate HRIT_MSG3_CTT
animate: unable to open X server `' @ animate.c/AnimateImageCommand/365.
+ animate HRIT_MSG3_IR108
animate: unable to open X server `' @ animate.c/AnimateImageCommand/365.
+ animate HRIT_MSG3_VIS006
animate: unable to open X server `' @ animate.c/AnimateImageCommand/365.
+ animate HRIT_MSG3_WV062
animate: unable to open X server `' @ animate.c/AnimateImageCommand/365.

请注意anim_all,当从终端手动调用时,它工作正常。此错误仅在由 cron 调用时存在。我想这与环境变量有关,但我已经.bashrc在脚本中找到了我的来源,但并没有占上风。

编辑 - 调查animate.c文件本身(请参阅此处的完整代码),在第 365-368 行,有这样的:

if (display == (Display *) NULL)
    ThrowAnimateException(XServerError,"UnableToOpenXServer",
    XDisplayName(server_name));
(void) XSetErrorHandler(XError);

作为回应,我试图$DISPLAY在脚本中将变量导出到 127.0.0.0:0 animate,但这没有奏效。

4

1 回答 1

2

您正在调用 ImageMagick 命令animate而不是您的脚本。在anim_all您应该使用animate脚本的完整路径。

/full/path/to/animate HRIT_MSG3_CTT

为了更好地衡量,我会更改 animate 的名称以消除进一步的混乱。

该错误提示我们正在发生的事情。开始 ImageMagickanimate需要一个 X 显示器,因为它有一个 GUI。此外,它说错误来自animate.c/AnimateImageCommand/365,当然是指这个文件。

于 2013-11-04T15:06:34.263 回答