Search code examples
cron

How to create a cron job using cron to grep some file


Does crontab have an argument for creating cron jobs using grep command to extract some data from text ?

this my command :

clog /var/log/messages.log | /usr/bin/grep -a user1 >> access.txt   

when i execute this command ; the file text access.txt will be created with the content i need

in cron job , the file will be created without content


Solution

  • You can set the full path to clog and access.txt to be sure what you run and where you write.

    Example cron record:

    5 10 * * * /usr/local/sbin/clog /var/log/messages.log | /usr/bin/grep -a user1 >> /path/to/access.txt