go 语言编译生成文件无法用 crontab 执行,sh -x 分析报错 cannot execute binary file,命令行下可以执行

2017-07-07 14:09:47 +08:00
 jimy1

aiFileTrans 程序每 2 分钟扫描读取解析文件,把解析的每行数据插入 MySQL 数据库。程序在终端可以运行。

aiFileTrans 程序权限是可执行的,就在本机上编译生成的包,但就是报错:cannot execute binary file,是不是我 crontab 需要声明环境变量呢?请大神指点,先谢谢了。 报错内容(重定向到 /root/1.txt )

[root@localhost bin]# cat /root/1.txt 
/root/tasks/go/fjgd/bin/aiFileTrans: /root/tasks/go/fjgd/bin/aiFileTrans: cannot execute binary file

crontab 内容如下:

*/2 * * * * sh -x /root/tasks/go/fjgd/bin/aiFileTrans -c /root/tasks/go/fjgd/bin/aiFileTrans.xml >/root/1.txt 2>&1
1312 次点击
所在节点    Go 编程语言
7 条回复
jimy1
2017-07-07 14:27:42 +08:00
我把 crontab 里面写的“-c -c /root/tasks/go/fjgd/bin/aiFileTrans.xml ”去掉,现在 crontab 内容
*/2 * * * * sh -x /root/tasks/go/fjgd/bin/aiFileTrans >/root/1.txt 2>&1
还是报错:
/root/tasks/go/fjgd/bin/aiFileTrans: /root/tasks/go/fjgd/bin/aiFileTrans: cannot execute binary file
julyclyde
2017-07-07 14:33:49 +08:00
你知道 sh -x 是什么意思吗?
bomb77
2017-07-07 14:37:12 +08:00
。。。。。。你二进制文件为什么要用 sh 去执行
直接执行就行了
如果还不成功,去看 /var/log/cron 里的日志
alex8
2017-07-07 14:42:51 +08:00
opcache.save_comments = 0;
就好了
jimy1
2017-07-07 14:43:14 +08:00
谢谢 @bomb77 的回复。

日志里面显示有这个 crontab 任务的执行记录,但是没有生成日志

sh 执行是为了分析为啥 crontab 不执行,是为了诊断,最终是想是想定时运行这个程序
jarlyyn
2017-07-07 14:49:30 +08:00
@jimy1

别人的意思是 sh -x 不能跑二进制程序

sh -x /bin/cp
/bin/cp: /bin/cp: cannot execute binary file
jimy1
2017-07-07 14:52:55 +08:00
哦,明白了,非常谢谢哈 @jarlyyn

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/373719

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX