0

When I'm running this command from shell(tcsh), it executes perfectly-

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"

But when I put the exact same thing in a crontab, I get this error mail from my machine-

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 . . .

I'm sure that even my crontab commands are executed using tcsh as it is set to be the default.

p.s- My machine: SunOS uatserver 5.10 Generic_127112-11 i86pc i386 i86pc

BenMorel
  • 34,448
  • 50
  • 182
  • 322
kaustav datta
  • 687
  • 2
  • 11
  • 31

1 Answers1

2

Your problem is that the PATH variable is not the same. Solaris has different flavors of grep examples:

/usr/bin/grep /usr/xpg4/bin/grep

You crontab ran /usr/bin/grep instead of /usr/xpg4/bin/grep. The two versions of grep have some different options.

jim mcnamara
  • 16,005
  • 2
  • 34
  • 51