-1

When I tried exection grep function in particular directory its working on that directory but when I am trying to execute using absolute paths grep is not working for example

 grep `date +%Y-%m-%d` /var/wwww/file/file.log >> /home/filename/file.log

The above command output getting as empty file.
Is it possible to schedule grep in crontab to match text and generate valid output ?

2
  • the question you linked, does not as far as I can see handle the % problem ... it is just a rather generic explanation Feb 18, 2015 at 8:08
  • you may want to edit the title of this question, to reflect the problem you ran into :) Mar 2, 2015 at 7:35

1 Answer 1

1

The % in your crontab file gets turned into a newline character unless escaped with a backslash. Try

grep `date +\%Y-\%m-\%d` /var/wwww/file/file.log >> /home/filename/file.log

see

man 5 crontab

for details.

4
  • its working great from command line but how to set this as cronjob ? do you think grep works inside cron ? Feb 18, 2015 at 7:17
  • its working as crob job too !!!! Feb 18, 2015 at 7:24
  • 1
    the % in the crontab problem happens to me every few years as I tend to forget this special handling :) Feb 18, 2015 at 8:06
  • It saved my day. I just want to write a bash script for automation for present day log. I am very noob in bash script so instead of going for bash script i thought about grep and cron. They just worked for me prefectly. Feb 18, 2015 at 8:11

Not the answer you're looking for? Browse other questions tagged .