LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 02:38 AM   #1
hruday
Member
 
Registered: Jun 2015
Posts: 84

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 02:46 AM.
 
Old 06-11-2015, 02:59 AM   #2
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,479

Rep: Reputation: 388Reputation: 388Reputation: 388Reputation: 388
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 03:00 AM.
 
Old 06-11-2015, 03:22 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,364

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

Rep: Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261
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 06:39 AM
[SOLVED] How to create a log file for a program laginagesh Linux - Software 1 08-22-2009 08:41 AM
Create log file against a script shipon_97 Linux - Newbie 1 01-02-2008 11:54 AM
How to create a log File using tee?? rmvinodh123 Programming 1 04-12-2007 02:21 AM
need to create log file sanjay2004 Linux - Newbie 6 02-27-2006 11:11 AM


All times are GMT -5. The time now is 07:41 PM.

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