LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 10-17-2008, 11:41 AM   #1
Azhrarn
Member
 
Registered: Aug 2005
Location: Europe
Posts: 63

Rep: Reputation: 15
Question Problem logging deleted files older than X


Hey all,
I m in a bit of a sticky situation.

I am using a linux ftp server of Dreamhost for my company to exchange files with the outside world, so I want files to be deleted after 10 days, when they have been successfully downloaded by the clients.

I m using this script:

Code:
#!/bin/bash
# Prints the date on the File
date > ~/cut-usa.com/Shared/clear_shared.log

# Moves to the shared folder
cd ~/cut-usa.com/Shared 

# Finds and deletes all files older than 10 days (9 days older than the last 24 hours)
echo "Deleting files older than 10 days:" >> ~/cut-usa.com/Shared/clear_shared.log
find . -mtime +9 -exec rm -fvr {} \; >> ~/cut-usa.com/Shared/clear_shared.log 

# Finds and deletes all folders that are empty
echo "Deleting folders:" >> ~/cut-usa.com/Shared/clear_shared.log
find * -type d -exec rmdir --verbose {} \; >> ~/cut-usa.com/Shared/clear_shared.log

# Prints operation concluded to file
echo "Operation Complete" >> ~/cut-usa.com/Shared/clear_shared.log
Now this code outputs none of the results of the "find" commands

Here s some other stuff I ve tried:

This outputs every folder, not only the deleted ones
Code:
find * -type d -print -exec rmdir {} \; >> file
This is the same of the original (does the job but logs nothing)
Code:
find * -type d -print -exec rmdir >> ~/cut-usa.com/Shared/clear_shared.log{} \;
I ve also tried removing all of the > and >> from the script and running the script like this
script > file.log

but again, nothing, it logs all of the echos but none of the results of the find commands.

Can anyone point me in the right direction?
Thanks
Paul
 
Old 10-17-2008, 09:41 PM   #2
ciotog
Member
 
Registered: Mar 2004
Location: Canada
Distribution: Slackware current
Posts: 728
Blog Entries: 2

Rep: Reputation: 43
Well I think the output of the find command is being swallowed up by the rmdir command. Maybe you could do something like the following:
Code:
#!/bin/bash
LOG=~/cut-usa.com/Shared/clear_shared.log
# Prints the date on the File
date > $LOG
# Moves to the shared folder
cd ~/cut-usa.com/Shared 

# Finds and deletes all files older than 10 days (9 days older than the last 24 hours)
echo "Deleting files older than 10 days:" >> $LOG
find . -mtime +9 -fprint $LOG -exec rm -fvr {} \;

# Finds and deletes all folders that are empty
echo "Deleting folders:" >> $LOG
find * -type d -fprint $LOG -exec rmdir --verbose {} \;

# Prints operation concluded to file
echo "Operation Complete" >> $LOG
 
Old 10-22-2008, 10:48 AM   #3
Azhrarn
Member
 
Registered: Aug 2005
Location: Europe
Posts: 63

Original Poster
Rep: Reputation: 15
Almost there!!

Hi Ciotog,
thanks for the help, it now works, but the log file simply skips everything before

find * -type d -fprint $LOG -exec rmdir --verbose {} \;

(the 3rd last line),
I m guessing the -fprint command does a > rather than an >>

Is there any way to append to the file rather than overwrite it?
Thanks a mil!
Paul
 
Old 10-22-2008, 02:21 PM   #4
ciotog
Member
 
Registered: Mar 2004
Location: Canada
Distribution: Slackware current
Posts: 728
Blog Entries: 2

Rep: Reputation: 43
I think this should work:
Code:
find * -type d -print -exec rmdir --verbose {} \; >>$LOG
I haven't tested it out, though.

Last edited by ciotog; 10-22-2008 at 02:22 PM. Reason: remove the quoted section
 
Old 10-24-2008, 09:04 AM   #5
Azhrarn
Member
 
Registered: Aug 2005
Location: Europe
Posts: 63

Original Poster
Rep: Reputation: 15
Works like a dream, of course how dumb of me... print out but not to file, then output the result of the command to file...
Doh!!!
Thanks
 
  


Reply

Tags
delete, exec, find, log


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
Script help - delete files older than 45 days but exclude the system files jojothedogboy Linux - Software 3 06-13-2008 04:43 PM
Mepis, copy files to thumb drive, files deleted? vremenno Linux - Newbie 6 09-16-2006 12:21 AM
Problem deleted all files in /tmp as root and can't start fedora 5 in Graphic mode meelmaar Linux - General 3 08-22-2006 03:33 AM
Problem in recovering deleted files (error : bad magic number) anamika123 Linux - Software 11 09-20-2004 05:55 AM
problem in recovering deleted files bad magic number anamika123 Linux - General 1 09-19-2004 03:09 PM


All times are GMT -5. The time now is 03:04 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration