- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: crontab entry to delete old files/folders erro...
Operating System - HP-UX
1753907
Members
8531
Online
108810
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-01-2010 06:46 AM
тАО12-01-2010 06:46 AM
crontab entry to delete old files/folders error
I am trying to automate the delete of a backup directory that is 14 days old
this is the crontab entry I am trying.
find /backup_to_disk/some_dir/ -depth -mtime +14 -exec sh -c 'test -d "$1" && rmdir "$1" || rm "$1"' {} {} \;
This is the error I am receiving
rmdir: /backup_to_disk/some_dir/11042010/prod/bakdir: Directory not empty
rm: /backup_to_disk/some_dir/11042010/prod/bakdir directory
Any ideas?
this is the crontab entry I am trying.
find /backup_to_disk/some_dir/ -depth -mtime +14 -exec sh -c 'test -d "$1" && rmdir "$1" || rm "$1"' {} {} \;
This is the error I am receiving
rmdir: /backup_to_disk/some_dir/11042010/prod/bakdir: Directory not empty
rm: /backup_to_disk/some_dir/11042010/prod/bakdir directory
Any ideas?
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-01-2010 07:01 AM
тАО12-01-2010 07:01 AM
Re: crontab entry to delete old files/folders error
> Any ideas?
Plain "rm" won't delete a directory. "rmdir"
won't delete a non-empty directory.
man rmdir
man rm
Look for "-r"?
> [...] test -d [...]
man find
Look for "-type"?
Plain "rm" won't delete a directory. "rmdir"
won't delete a non-empty directory.
man rmdir
man rm
Look for "-r"?
> [...] test -d [...]
man find
Look for "-type"?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-01-2010 09:31 AM
тАО12-01-2010 09:31 AM
Re: crontab entry to delete old files/folders error
Hi:
The case of the error on a non-empty directory (from 'rmdir') is the result of 'find' having found a directory that meets the criteria but yet none of its contents (files) satisfy the criteria.
It might be better to use a two-step process where you first remove *files* ('-type f') and then, in a second pass attempt to remove directories ('-type d') ignoring non-empty errors.
Regards!
...JRF...
The case of the error on a non-empty directory (from 'rmdir') is the result of 'find' having found a directory that meets the criteria but yet none of its contents (files) satisfy the criteria.
It might be better to use a two-step process where you first remove *files* ('-type f') and then, in a second pass attempt to remove directories ('-type d') ignoring non-empty errors.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-01-2010 11:26 AM
тАО12-01-2010 11:26 AM
Re: crontab entry to delete old files/folders error
>JRF: in a second pass attempt to remove directories ('-type d') ignoring non-empty errors.
Right, the first pass may cause the directory to be modified and 14 more days must go by before you finally remove that. But that shouldn't take up too much space.
Or if you assume only new files are added, the directory is always modified at the same date so you can just use rm -rf.
Right, the first pass may cause the directory to be modified and 14 more days must go by before you finally remove that. But that shouldn't take up too much space.
Or if you assume only new files are added, the directory is always modified at the same date so you can just use rm -rf.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP