V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
jimy1
V2EX  ›  Go 编程语言

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

  •  
  •   jimy1 · 2017-07-07 14:09:47 +08:00 · 1296 次点击
    这是一个创建于 2478 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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
    
    7 条回复    2017-07-07 14:52:55 +08:00
    jimy1
        1
    jimy1  
    OP
       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
        2
    julyclyde  
       2017-07-07 14:33:49 +08:00
    你知道 sh -x 是什么意思吗?
    bomb77
        3
    bomb77  
       2017-07-07 14:37:12 +08:00
    。。。。。。你二进制文件为什么要用 sh 去执行
    直接执行就行了
    如果还不成功,去看 /var/log/cron 里的日志
    alex8
        4
    alex8  
       2017-07-07 14:42:51 +08:00
    opcache.save_comments = 0;
    就好了
    jimy1
        5
    jimy1  
    OP
       2017-07-07 14:43:14 +08:00
    谢谢 @bomb77 的回复。

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

    sh 执行是为了分析为啥 crontab 不执行,是为了诊断,最终是想是想定时运行这个程序
    jarlyyn
        6
    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
        7
    jimy1  
    OP
       2017-07-07 14:52:55 +08:00
    哦,明白了,非常谢谢哈 @jarlyyn
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1007 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 19:01 · PVG 03:01 · LAX 12:01 · JFK 15:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.