LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-11-2015, 03:38 AM   #1
hruday
Member
 
Registered: Jun 2015
Posts: 87

Rep: Reputation: Disabled
how to create a log file for a cronjob?


I have written my cron job as
00 23 * * * find /home/backup/*.dump -type f -mtime +30 -exec rm {} \;
this job will delete all files older than 30 days. now how to log those deleted files in a separate log file?

Last edited by hruday; 06-11-2015 at 03:46 AM.
 
Old 06-11-2015, 03:59 AM   #2
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,517

Rep: Reputation: 397Reputation: 397Reputation: 397Reputation: 397
Code:
00 23 * * * find /home/backup/*.dump -type f -mtime +30 -exec rm {} \; >> /my/logfile
maybe?

Last edited by descendant_command; 06-11-2015 at 04:00 AM.
 
Old 06-11-2015, 04:22 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,879

Rep: Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910
you can also add 2>&1 at the end
 
Old 06-11-2015, 08:30 AM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,714

Rep: Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280
I think you will need a "-print" to tell find to output the file name...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create log file from script fotoguy Programming 12 03-27-2012 07:39 AM
[SOLVED] How to create a log file for a program laginagesh Linux - Software 1 08-22-2009 09:41 AM
Create log file against a script shipon_97 Linux - Newbie 1 01-02-2008 12:54 PM
How to create a log File using tee?? rmvinodh123 Programming 1 04-12-2007 03:21 AM
need to create log file sanjay2004 Linux - Newbie 6 02-27-2006 12:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration