免费注册 查看新帖 |

Chinaunix

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

Shell 脚本手动运行没有问题,CRONTAB 里刚开始没有问题,后来就显示SYNTAX ERROR. [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-10-01 10:50 |只看该作者 |倒序浏览
Shell 脚本手动运行没有问题,放到CRONTAB 里刚开始没有问题,后来就显示SYNTAX ERROR

请高手看看给点意见。。。。

#!/bin/bash
pidlist1=`ps aux|grep abc|grep -v "grep"|awk '{print $2}'`
pidlist2=`ps aux|grep tcpdump|grep -v "grep"|awk '{print $2}'`
#pidstat=`ps aux|grep abc|grep $USER|grep -v "grep"|awk '{print $8}'`
tcpport=`netstat -ant|grep 44026|awk '{print $4}'|cut -f 2 -d ":"`

file=/root/log3

function checktcpdump {
     /bin/ps aux|grep -v "grep"|grep tcpdump|awk '{print $2}' >$file      
     if [ -s $file ]
     then
     killabc
     killtcpdump
     startabc
     else
     starttcpdump
     fi
}

function starttcpdump {
     echo `date +%F" "%r`": tcpdump started success!" >/var/log/tcpdump.log
      /usr/sbin/tcpdump -c 2 tcp port $tcpport >/root/tcptest
}

function startabc {
     echo `date +%F" "%r`": abc started success!" >>/var/log/eftpos.log
     /home/user/test/abc
}

function killtcpdump {
     echo `date +%F" "%r`": tcpdump was killed!" >>/var/log/tcpdump.log1
     /bin/kill -9 $pidlist2
}

function killabc {
      echo `date +%F" "%r`": abc was killed!" >>/var/log/eftpos.log
     /bin/kill -9 $pidlist1
}

function testabc {
     /bin/ps aux|grep abc|grep -v "grep"|awk '{print $2}' >$file
     if [ -s $file ]
     then
      echo `date`": first condition is fine!" >/root/log2
     else
      /home/user/test/abc
#      echo `date +%r%F`": abc started success!" >>/var/log/eftpos.log
     fi
}

checktcpdump

论坛徽章:
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
2 [报告]
发表于 2010-10-01 11:01 |只看该作者
* * * * * /test.sh >/tmp/test.log 2>&1
看看日志

论坛徽章:
0
3 [报告]
发表于 2010-10-01 11:07 |只看该作者
* * * * * /test.sh >/tmp/test.log 2>&1
看看日志
Shell_HAT 发表于 2010-10-01 11:01



你是指加个日志在CRONTAB 里面? 到时有问题,看看日志显示的什么错误?

论坛徽章:
0
4 [报告]
发表于 2010-10-02 14:13 |只看该作者
怎么好冷啊。。都没有什么人了。。。。。

论坛徽章:
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
5 [报告]
发表于 2010-10-02 14:29 |只看该作者
回复 3# Shrek618


看到错误了?
dragon23452345 该用户已被删除
6 [报告]
发表于 2010-10-02 16:44 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
7 [报告]
发表于 2010-10-19 18:58 |只看该作者
回复 5# Shell_HAT


我在crontab里面做了你说的LOG,显示的还是SYNTAX ERROR..  你觉得最可能的是什么问题?

论坛徽章:
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 [报告]
发表于 2010-10-19 20:31 |只看该作者
回复 7# Shrek618


日志内容贴出来看看

论坛徽章:
0
9 [报告]
发表于 2010-10-20 13:25 |只看该作者
回复 8# Shell_HAT


Server:~# cat crontab.log
tcpdump:syntax error

就上面这点,它都没有确切的显示是什么地方的错误。。这是什么原因?

论坛徽章:
0
10 [报告]
发表于 2010-10-20 13:47 |只看该作者
本帖最后由 ywlscpl 于 2010-10-20 13:49 编辑

/usr/sbin/tcpdump -c 2 tcp port $tcpport >/root/tcptest

$tcport变量为空或为非预期值导致tcpdump语句语法错误
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP