- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: find command returns error if it cant find fil...
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
Discussions
Discussions
Forums
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
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
тАО05-09-2009 07:27 AM
тАО05-09-2009 07:27 AM
00 5 * * * find /dir/*dump/*.trc -mtime +14 -exec rm {} \;
Which is fine, but find complains if the directory is not there. Which in some cases it wont be.
produced the following output:
find: stat() error/dir/*dump/*.trc: No such file or directory
How do I run this find command in my cron, and not produce an error if it /dir/*dump/ does not exist?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-09-2009 07:45 AM
тАО05-09-2009 07:45 AM
Solution# 00 5 * * * find /dir/*dump/*.trc -mtime +14 -exec rm {} \; 2> /dev/null
...will suppress the STDERR output you are seeing.
TO make your removal faster. The '-exec' terminated with a semicolon will spawn a process for every file found. Using the '+' terminator causes the bundling of many arguments (here, file names) together and then creating one or just a few processes to remove them.
# 00 5 * * * find /dir/*dump/*.trc -mtime +14 -exec rm {} + 2> /dev/null
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-09-2009 11:08 AM
тАО05-09-2009 11:08 AM
Re: find command returns error if it cant find file
You don't. You run something better. (Write
a script which does what you want?)
You could test for the directory/ies before
running the "find" command.
If a "/dir/*dump" was always there, but the
"*.trc" part was uncertain, then you might
do something like:
find /dir/*dump -name '*.trc'
Using a file-spec wildcard in a "find"
command is often a sign of a poor design.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-09-2009 12:35 PM
тАО05-09-2009 12:35 PM
Re: find command returns error if it cant find file
You may also want to improve it by finding only files "-type f" and/or adding "-f" or "-rf" to your rm:
find /dir/*dump/*.trc -mtime +14 -exec rm -rf {} + 2> /dev/null
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-09-2009 04:27 PM
тАО05-09-2009 04:27 PM