Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
2  
Is there a good reason not to just package that command line into a shell script file? –  rackandboneman Jan 11 '13 at 10:33
add comment

1 Answer 1

up vote 1 down vote accepted

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
share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.