免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2492 | 回复: 8
打印 上一主题 下一主题

[系统管理] crontab不执行,报错:cannot execute binary file,是环境变量问题吗?命令行可以执行 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2017-07-07 09:41 |只看该作者 |倒序浏览

试了2次,不运行crontab任务,请大神指点,先谢谢了。

第一次crontab内容如下:
  1. */2 * * * * /tmp/aiFileTrans -c /tmp/aiFileTrans.xml >/root/1.txt 2>&1
复制代码
/root/1.txt 的内容(报错信息)为:
  1. /tmp/aiFileTrans: /tmp/aiFileTrans: cannot execute binary file
复制代码
第二次crontab内容如下:
  1. */2 * * * * sh -x /tmp/cp_file3.sh >/root/1.txt 2>&1
复制代码
cp_file3.sh内容如下:
  1. !/bin/bash
  2. . /etc/profile
  3. . ~/.bash_profile
  4. /tmp/aiFileTrans -c /tmp/aiFileTrans.xml
复制代码
/root/1.txt 的内容(报错信息)为(每行加上了编号):
  1.       1 + '!/bin/bash'
  2.       2 /tmp/cp_file3.sh: line 1: !/bin/bash: No such file or directory
  3.       3 + . /etc/profile
  4.       4 ++ '[' -x /usr/bin/id ']'
  5.       5 ++ '[' -z 0 ']'
  6.       6 +++ /usr/bin/id -un
  7.       7 ++ USER=root
  8.       8 ++ LOGNAME=root
  9.       9 ++ MAIL=/var/spool/mail/root
  10.      10 ++ '[' 0 = 0 ']'
  11.      11 ++ pathmunge /sbin
  12.      12 ++ case ":${PATH}:" in
  13.      13 ++ '[' '' = after ']'
  14.      14 ++ PATH=/sbin:/usr/bin:/bin
  15.      15 ++ pathmunge /usr/sbin
  16.      16 ++ case ":${PATH}:" in
  17.      17 ++ '[' '' = after ']'
  18.      18 ++ PATH=/usr/sbin:/sbin:/usr/bin:/bin
  19.      19 ++ pathmunge /usr/local/sbin
  20.      20 ++ case ":${PATH}:" in
  21.      21 ++ '[' '' = after ']'
  22.      22 ++ PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/bin:/bin
  23.      23 +++ /bin/hostname
  24.      24 ++ HOSTNAME=37f8bbce7b38
  25.      25 ++ HISTSIZE=1000
  26.      26 ++ '[' '' = ignorespace ']'
  27.      27 ++ export HISTCONTROL=ignoredups
  28.      28 ++ HISTCONTROL=ignoredups
  29.      29 ++ export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
  30.      30 ++ '[' 0 -gt 199 ']'
  31.      31 ++ umask 022
  32.      32 ++ for i in '/etc/profile.d/*.sh'
  33.      33 ++ '[' -r /etc/profile.d/colorls.sh ']'
  34.      34 ++ '[' hxB '!=' hxB ']'
  35.      35 ++ . /etc/profile.d/colorls.sh
  36.      36 ++ for i in '/etc/profile.d/*.sh'
  37.      37 ++ '[' -r /etc/profile.d/glib2.sh ']'
  38.      38 ++ '[' hxB '!=' hxB ']'
  39.      39 ++ . /etc/profile.d/glib2.sh
  40.      40 ++ for i in '/etc/profile.d/*.sh'
  41.      41 ++ '[' -r /etc/profile.d/lang.sh ']'
  42.      42 ++ '[' hxB '!=' hxB ']'
  43.      43 ++ . /etc/profile.d/lang.sh
  44.      44 ++ for i in '/etc/profile.d/*.sh'
  45.      45 ++ '[' -r /etc/profile.d/less.sh ']'
  46.      46 ++ '[' hxB '!=' hxB ']'
  47.      47 ++ . /etc/profile.d/less.sh
  48.      48 ++ unset i
  49.      49 ++ unset -f pathmunge
  50.      50 + . /root/.bash_profile
  51.      51 ++ '[' -f /root/.bashrc ']'
  52.      52 ++ . /root/.bashrc
  53.      53 +++ alias 'rm=rm -i'
  54.      54 +++ alias 'cp=cp -i'
  55.      55 +++ alias 'mv=mv -i'
  56.      56 +++ '[' -f /etc/bashrc ']'
  57.          57 +++ . /etc/bashrc
  58.      58 ++++ '[' '' ']'
  59.      59 ++++ shopt -q login_shell
  60.      60 ++++ '[' 0 -gt 199 ']'
  61.      61 ++++ umask 022
  62.      62 ++++ for i in '/etc/profile.d/*.sh'
  63.      63 ++++ '[' -r /etc/profile.d/colorls.sh ']'
  64.      64 ++++ '[' '' ']'
  65.      65 ++++ . /etc/profile.d/colorls.sh
  66.      66 ++++ for i in '/etc/profile.d/*.sh'
  67.      67 ++++ '[' -r /etc/profile.d/glib2.sh ']'
  68.      68 ++++ '[' '' ']'
  69.      69 ++++ . /etc/profile.d/glib2.sh
  70.      70 ++++ for i in '/etc/profile.d/*.sh'
  71.      71 ++++ '[' -r /etc/profile.d/lang.sh ']'
  72.      72 ++++ '[' '' ']'
  73.      73 ++++ . /etc/profile.d/lang.sh
  74.      74 ++++ for i in '/etc/profile.d/*.sh'
  75.      75 ++++ '[' -r /etc/profile.d/less.sh ']'
  76.      76 ++++ '[' '' ']'
  77.      77 ++++ . /etc/profile.d/less.sh
  78.      78 ++++ unset i
  79.      79 ++++ unset pathmunge
  80.      80 ++ PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/bin:/bin:/root/bin
  81.      81 ++ export PATH
  82.      82 + /tmp/aiFileTrans -c /tmp/aiFileTrans.xml
复制代码


论坛徽章:
0
2 [报告]
发表于 2017-07-07 09:54 |只看该作者
本帖最后由 apsufhvk 于 2017-07-07 10:04 编辑

第一个应该是权限问题 chmod +x
第二个脚本开头是 #!/bin/bash,少了#

论坛徽章:
0
3 [报告]
发表于 2017-07-07 10:33 |只看该作者
谢谢@apsufhvk 的回复。
权限我之前加过可执行的:
  1. [root@37f8bbce7b38 tmp]# ll aiFileTrans
  2. -rwxr-xr-x 1 root root 4768473 Jul  3 19:20 aiFileTrans
复制代码


第二个我加上#后,/root/1.txt 的内容至少了2行/bin/bash报错,其他一样,但/tmp/aiFileTrans -c /tmp/aiFileTrans.xml 还是没执行:
/root/1.txt 的内容(报错信息)为(每行加上了编号):
  1.       1 + . /etc/profile
  2.       2 ++ '[' -x /usr/bin/id ']'
  3.       3 ++ '[' -z 0 ']'
  4.       4 +++ /usr/bin/id -un
  5.       5 ++ USER=root
  6.       6 ++ LOGNAME=root
  7.       7 ++ MAIL=/var/spool/mail/root
  8.       8 ++ '[' 0 = 0 ']'
  9.       9 ++ pathmunge /sbin
  10.      10 ++ case ":${PATH}:" in
  11.      11 ++ '[' '' = after ']'
  12.      12 ++ PATH=/sbin:/usr/bin:/bin
  13.      13 ++ pathmunge /usr/sbin
  14.      14 ++ case ":${PATH}:" in
  15.      15 ++ '[' '' = after ']'
  16.      16 ++ PATH=/usr/sbin:/sbin:/usr/bin:/bin
  17.      17 ++ pathmunge /usr/local/sbin
  18.      18 ++ case ":${PATH}:" in
  19.      19 ++ '[' '' = after ']'
  20.      20 ++ PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/bin:/bin
  21.      21 +++ /bin/hostname
  22.      22 ++ HOSTNAME=37f8bbce7b38
  23.      23 ++ HISTSIZE=1000
  24.      24 ++ '[' '' = ignorespace ']'
  25.      25 ++ export HISTCONTROL=ignoredups
  26.      26 ++ HISTCONTROL=ignoredups
  27.      27 ++ export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
  28.      28 ++ '[' 0 -gt 199 ']'
  29.      29 ++ umask 022
  30.      30 ++ for i in '/etc/profile.d/*.sh'
  31.      31 ++ '[' -r /etc/profile.d/colorls.sh ']'
  32.      32 ++ '[' hxB '!=' hxB ']'
  33.      33 ++ . /etc/profile.d/colorls.sh
  34.      34 ++ for i in '/etc/profile.d/*.sh'
  35.      35 ++ '[' -r /etc/profile.d/glib2.sh ']'
  36.      36 ++ '[' hxB '!=' hxB ']'
  37.      37 ++ . /etc/profile.d/glib2.sh
  38.      38 ++ for i in '/etc/profile.d/*.sh'
  39.      39 ++ '[' -r /etc/profile.d/lang.sh ']'
  40.      40 ++ '[' hxB '!=' hxB ']'
  41.      41 ++ . /etc/profile.d/lang.sh
  42.      42 ++ for i in '/etc/profile.d/*.sh'
  43.      43 ++ '[' -r /etc/profile.d/less.sh ']'
  44.      44 ++ '[' hxB '!=' hxB ']'
  45.      45 ++ . /etc/profile.d/less.sh
  46.      46 ++ unset i
  47.      47 ++ unset -f pathmunge
  48.      48 + . /root/.bash_profile
  49.      49 ++ '[' -f /root/.bashrc ']'
  50.      50 ++ . /root/.bashrc
  51.      51 +++ alias 'rm=rm -i'
  52.      52 +++ alias 'cp=cp -i'
  53.      53 +++ alias 'mv=mv -i'
  54.      54 +++ '[' -f /etc/bashrc ']'
  55.      55 +++ . /etc/bashrc
  56.      56 ++++ '[' '' ']
  57.      57 ++++ shopt -q login_shell
  58.      58 ++++ '[' 0 -gt 199 ']'
  59.      59 ++++ umask 022
  60.      60 ++++ for i in '/etc/profile.d/*.sh'
  61.      61 ++++ '[' -r /etc/profile.d/colorls.sh ']'
  62.      62 ++++ '[' '' ']'
  63.      63 ++++ . /etc/profile.d/colorls.sh
  64.      64 ++++ for i in '/etc/profile.d/*.sh'
  65.      65 ++++ '[' -r /etc/profile.d/glib2.sh ']'
  66.      66 ++++ '[' '' ']'
  67.      67 ++++ . /etc/profile.d/glib2.sh
  68.      68 ++++ for i in '/etc/profile.d/*.sh'
  69.      69 ++++ '[' -r /etc/profile.d/lang.sh ']'
  70.      70 ++++ '[' '' ']'
  71.      71 ++++ . /etc/profile.d/lang.sh
  72.      72 ++++ for i in '/etc/profile.d/*.sh'
  73.      73 ++++ '[' -r /etc/profile.d/less.sh ']'
  74.      74 ++++ '[' '' ']'
  75.      75 ++++ . /etc/profile.d/less.sh
  76.      76 ++++ unset i
  77.      77 ++++ unset pathmunge
  78.      78 ++ PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/bin:/bin:/root/bin
  79.      79 ++ export PATH
  80.      80 + /tmp/aiFileTrans -c /tmp/aiFileTrans.xm
复制代码

论坛徽章:
39
辰龙
日期:2013-08-21 15:45:192015亚冠之广州富力
日期:2015-05-12 16:34:52亥猪
日期:2015-03-03 17:22:00申猴
日期:2015-03-03 17:21:37未羊
日期:2014-10-10 13:45:41戌狗
日期:2014-06-17 09:53:29巨蟹座
日期:2014-06-12 23:17:17双鱼座
日期:2014-06-10 12:42:44寅虎
日期:2014-06-09 12:52:172015亚冠之卡尔希纳萨夫
日期:2015-05-24 15:24:35黄金圣斗士
日期:2015-12-02 17:25:0815-16赛季CBA联赛之吉林
日期:2017-06-24 16:43:52
4 [报告]
发表于 2017-07-07 11:06 |只看该作者
有日志记录就是crontab已经执行了, 只是没得到你想要的结果而已,  /tmp/aiFileTrans -c /tmp/aiFileTrans.xm  这个命令在终端下能不能执行成功?  输出结果是什么?

论坛徽章:
0
5 [报告]
发表于 2017-07-07 11:39 |只看该作者
谢谢@关阴月飞,我发现问题还在  cannot execute binary file

我用*/2 * * * * sh -x /root/tasks/go/fjgd/bin/aiFileTrans -c /root/tasks/go/fjgd/bin/aiFileTrans.xml >/root/1.txt 2>&1
在/root/1.txt里面显示:
  1. /root/tasks/go/fjgd/bin/aiFileTrans: /root/tasks/go/fjgd/bin/aiFileTrans: cannot execute binary file
复制代码

论坛徽章:
0
6 [报告]
发表于 2017-07-07 13:45 |只看该作者
在终端中没有输出,是一个文件读取解析程序,解析完文件后把文件内容行插入到MySQL数据库表里面

论坛徽章:
0
7 [报告]
发表于 2017-07-07 13:47 |只看该作者
在终端可以运行,这个程序读取解析这个文件,把解析的每行数据插入MySQL数据库,会写日志,但现在没有看到日志更新

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
8 [报告]
发表于 2017-07-07 16:50 |只看该作者
/root/tasks/go/fjgd/bin/aiFileTrans -c /root/tasks/go/fjgd/bin/aiFileTrans.xml
这个命令在终端成功执行是用的root用户吗?试试这样:
/root/1.sh
  1. #!/bin/bash
  2. . /etc/profile
  3. . /root/.bash_profile
  4. /root/tasks/go/fjgd/bin/aiFileTrans -c /root/tasks/go/fjgd/bin/aiFileTrans.xml
复制代码

chmod +x /root/1.sh

crontab
  1. */2 * * * * /root/1.sh >/root/1.txt 2>&1
复制代码


另外,把这个权限发出来看看:
  1. ls -l /root/tasks/go/fjgd/bin/aiFileTrans
复制代码

论坛徽章:
0
9 [报告]
发表于 2017-07-13 14:56 |只看该作者
谢谢版主详细的回答,照你建议的已经可以运行了,谢谢 @Shell_HAT
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP