从cron运行命令时出错(tcsh)

时间:2012-11-21 08:35:15

标签: unix crontab tcsh

当我从shell(tcsh)运行此命令时,它执行完美 -

cal | tail -6 | sed -e 's/^.\{3\}//' -e 's/.\{3\}$//' | tr -s '[:blank:]' '\n' | head -21 | tail -20 | tr -s '\n' ' ' | grep -w `date "+%e"` ; /usr/bin/bash -lc "if [ "$?" == 0 ] ; then echo xyz ; fi"

但是当我把完全相同的东西放在crontab中时,我从我的机器上收到了这个错误邮件 -

Subject: Output from "cron" command
Content-Length: 244

Your "cron" job on uatserver
cal | tail -6 | sed -e 's/^.\{3\}//' -e 's/.\{3\}$//' | tr -s '[:blank:]' '\n' | head -21 | tail -20 | tr -s '\n' ' ' | grep -w `date "+

produced the following output:

Usage: grep -hblcnsviw pattern file . . .

我确信即使我的crontab命令也是使用tcsh执行的,因为它被设置为默认值。

p.s-我的机器: SunOS uatserver 5.10 Generic_127112-11 i86pc i386 i86pc

1 个答案:

答案 0 :(得分:2)

你的问题是PATH变量不一样。 Solaris有不同的grep风格 示例:

的/ usr /斌/ grep的 的/ usr / XPG4 /斌/ grep的

你crontab运行/ usr / bin / grep而不是/ usr / xpg4 / bin / grep。 grep的两个版本有一些不同的选项。