0

The following is working as expected at command prompt. But it does not work from cron.

# echo "test abc xyz" | grep "test1 \| pqr"

# echo "test abc xyz" | grep "test \| pqr"
test abc xyz

When I use this statement in the cron, I need to escape certain characters. But I am not able to figure it out.

shantanuo
  • 3,579
  • 8
  • 49
  • 66

1 Answers1

1

I am not seeing any issue when I am trying to put it in cron. Are you trying to do the same like following:

[sgeorge@sgeorge-ld ~]$ crontab -l
MAILTO=suku@xxxxxx.com
* * * * * /bin/echo "test abc xyz" | grep "test \| pqr" >> stack
* * * * * /bin/echo "test abc xyz" | grep "test1 \| pqr" >> stack_with_1

[sgeorge@sgeorge-ld ~]$ ls -l stack*
-rw-r--r-- 1 sgeorge eng 13 Jan 11 02:45 stack
-rw-r--r-- 1 sgeorge eng  0 Jan 11 02:45 stack_with_1

[sgeorge@sgeorge-ld ~]$ cat stack_with_1 
[sgeorge@sgeorge-ld ~]$ cat stack
test abc xyz
Suku
  • 2,036
  • 13
  • 15
  • In my case it works only if there is no space. for e.g. "test1\|pqr". But you are correct, there is no need of escaping in this case. – shantanuo Jan 11 '13 at 11:22