- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: schedule cron
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
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
Community
Resources
Forums
Blogs
- 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
04-12-2007 06:32 AM
04-12-2007 06:32 AM
schedule cron
Thanks
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2007 06:34 AM
04-12-2007 06:34 AM
Re: schedule cron
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2007 06:35 AM
04-12-2007 06:35 AM
Re: schedule cron
01 01 * * 01 /usr/bin/find /tmp/PSFTP -type f -mtime +2 -exec rm {} \;
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2007 06:38 AM
04-12-2007 06:38 AM
Re: schedule cron
For files:
find /starting-dir -type f -mtime +2 -exec rm -f {}+
For dirs:
find /starting-dir -type d -mtime +2 -exec rm -f {}+
You can then either put those 2 commands in a script and then schedule that via cron, or you can just use those 2 lines as a command in cron and schedule them separately.
To learn how to schedule in cron I suggest perusing the crontab man page (man crontab).
Regarding the above finds, I would also advise doing a 'exec ll -d {}+' prior so you know how find will behave before you actually do the removal.
Once the file is deleted, you have no recourse for getting it back other than restoring from backup.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2007 06:58 AM
04-12-2007 06:58 AM
Re: schedule cron
I agree with Patrick insofar as you said "files" and "directories", but for directory removal you should use 'rmdir':
# find /starting-dir -type d -mtime +2 -exec rmdir {} \+
Note that the "+" character terminates the '-exec command' and like the use of the semicolon in Pete's post *must* be escaped for the shell.
The "+" terminator is available in 11.11 and later and is faster than the semicolon (";") terminator because it bundles multiple arguments together and passes the bundle to the command to run rather than spawning one command for each argument. The same goal can be met by piping to 'xargs'.
Regards!
...JRF...
#
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2007 03:33 PM
04-12-2007 03:33 PM
Re: schedule cron
If you use rmdir, you need to be prepared for non-empty directory errors.
I suppose removing the files, will touch the directory, so they will be empty first. But you could use:
# find /starting-dir -type d -mtime +2 -exec rmdir {} + 2> /dev/null
>Note that the "+" character terminates the '-exec command' and like the use of the semicolon in Pete's post *must* be escaped for the shell.
I asked before, what shell requires "+" to be escaped?? Neither sh nor ksh require it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2007 12:25 AM
04-16-2007 12:25 AM
Re: schedule cron
Dennis > JRF: But for directory removal you should use 'rmdir': If you use rmdir, you need to be prepared for non-empty directory errors.
Exactly. Depending upon the user's objectives, one may want to remove *files* older than n-days; remove empty directories, too; and leave non-empty ones. The statement of requirements needs to be clearer.
As for my comments regarding escaping the "+" terminator, I base them on the 'find(1)' manpages (either for 11.11, 11.23 or 11.31) that note under the discussion of '-exec cmd':
/* begin quote */
The end of cmd must be punctuated by a semicolon (;) or a plus sign (+) (semicolon and plus are special to the shell and must be escaped).
/* end quote */
I agree, however, that the absence of the escape character, in practice, doesn't seem to matter.
Regards!
...JRF...