LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Problem logging deleted files older than X (https://www.linuxquestions.org/questions/linux-software-2/problem-logging-deleted-files-older-than-x-677113/)

Azhrarn 10-17-2008 10:41 AM

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

ciotog 10-17-2008 08:41 PM

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


Azhrarn 10-22-2008 09:48 AM

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

ciotog 10-22-2008 01:21 PM

I think this should work:
Code:

find * -type d -print -exec rmdir --verbose {} \; >>$LOG
I haven't tested it out, though.

Azhrarn 10-24-2008 08:04 AM

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 :D


All times are GMT -5. The time now is 06:45 AM.