【问题标题】:Script works fine manually but not working on crontab脚本手动工作正常,但不能在 crontab 上工作
【发布时间】:2018-05-06 08:05:39
【问题描述】:

我的脚本正在手动运行,但无法在 crontab 上运行。我阅读了有关此问题的所有主题,我尝试了很多事情来通过 crontab 执行,但没有成功。

我的脚本在下面。

#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
nodetool status > cqlsh_control.txt
cs1=`more cqlsh_control.txt | awk '{print $1}' | sed -ne 6p | cut -d"%" -f1`
SLACK_ICON=":red_circle:"
if [ "$cs1" != "UN" ]; then

curl -S -X POST --data "payload={\"text\": \"{Cqlsh is not responsing Cassandra2}  \",\"username\":\"CQLSH\",\"icon_emoji\":\"${SLACK_ICON}\"
}" https://hooks.slack.com/services/T05xxxxW/B7xxxxxx09/QdotCzoxxxxxxxHxOsrnjS

fi

【问题讨论】:

  • 当你说>没有工作具体发生了什么?此外,您的 crontab 是什么样的?
  • 我的 crontab */1 * * * * /home/ec2-user/cqlsh_control.sh 并添加它尝试不同的组合 crontab */1 * * * * sh /home/ec2-user/ cqlsh_control.sh
  • 在您的 crontab 中,添加:>/tmp/out1 2>/tmp/out2。这样,您将看到脚本遇到的输出和错误。还要检查您的电子邮件,crontab 将脚本的输出邮寄出去。另一件事,*/1* 相同,因为 crontab 的运行频率不会超过每分钟一次。
  • 可能与stackoverflow.com/questions/20582224/… 重复,但另请参阅crontab tag wiki 中的故障排除说明。

标签: linux bash shell cassandra cqlsh


【解决方案1】:

编辑 crontab 并将 shell /bin/sh 放在脚本之前,如下所示。

*/1 * * * * /bin/sh /home/ec2-user/cqlsh_control.s

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-10
  • 2013-08-31
  • 1970-01-01
  • 1970-01-01
  • 2013-09-15
相关资源
最近更新 更多