Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 346
  • Last Modified:

How to move files that are older than 2 days

Does anybody know how to modify a script i run to grab all files older than 2 days?

Here is my current code

mv -f -u /mnt/test/* /mnt/test2 || mail -s "Scotts move has failed" scotts@cms-email.com < /dev/null

And I don't think that tmpwatch is the answer
0
shasta247
Asked:
shasta247
  • 2
  • 2
1 Solution
 
jlevieCommented:
cd /mnt/test
find . -ctime +2 -exec mv {} test2 \;
0
 
shasta247Author Commented:
Excellent - thanks jlevie!
0
 
shasta247Author Commented:
do you know how to make the script email me if it doesn't find anything?
0
 
jlevieCommented:
I assume you mean if there weren't any files older than 2 days in /mnt/test. The shell script below should do that:

#!/bin/sh
cd /mnt/test
cnt=`find . -ctime +2 | wc -l`
if [ $cnt -gt 0 ]; then
  find . -ctime +2 -exec mv {} ../test2 \;
else
  echo "No files found older than 2 days" | mail -s "Scotts move has failed" scotts@cms-email.com
fi
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now