- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Unix shell script for bash shell #!bin/sh to delet...
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
03-19-2001 07:54 AM
03-19-2001 07:54 AM
Unix shell script for bash shell #!bin/sh to delete the log files after 3 days.
files are in this format xxxxxx-010317-105729-02-17215.log
I am beginner and don't have much idea about scripting.
Please help me
Thanks in advance
Sandy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2001 08:02 AM
03-19-2001 08:02 AM
Re: Unix shell script for bash shell #!bin/sh to delete the log files after 3 days.
you could do it with the find command:
find
The above line will remove all files in
For testing you could do:
find
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2001 08:06 AM
03-19-2001 08:06 AM
Re: Unix shell script for bash shell #!bin/sh to delete the log files after 3 days.
just an addition to make it safer:
find
This will look only for files which ends with .log
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2001 08:10 AM
03-19-2001 08:10 AM
Re: Unix shell script for bash shell #!bin/sh to delete the log files after 3 days.
minute hour day month "day of week" command
For this, you could set it up daily to run at 5:00 pm (17:00), for example, every day of the week. This would be
0 17 * * * find
The * denotes all, so this line would mean every day of the month, every month, every day of the week. You can set this up to run whatever fits your needs. Hope this helps!
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2001 08:11 AM
03-19-2001 08:11 AM
Re: Unix shell script for bash shell #!bin/sh to delete the log files after 3 days.
Just as the king said:
Go to the directory containing the log files (or the directory underneeth).
find ./ -name "*.log" -mtime +3 -exec rm{} \;
You have a few parameters with the find command of which these are frequently used:
-atime : access time (days)
-mtime : modified time (days)
-name : find certain filename
-exec : executes a command for every file found
For more info type man find.
Regards,
DD
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2001 09:19 AM
03-19-2001 09:19 AM
Re: Unix shell script for bash shell #!bin/sh to delete the log files after 3 days.
find
like this by going to the particular directory where log file exist but it didn't work
find *.log -mtime +5 | xargs rm -f
Please help me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2001 09:42 AM
03-19-2001 09:42 AM
Re: Unix shell script for bash shell #!bin/sh to delete the log files after 3 days.
When using the '-atime' '-mtime' or '-ctime' options of 'find', a "day" is a 24-hour period. For example, 'find' will fail to deliver a file that has been modified less than 24-hours ago if the '-mtime' option is used with '+1'.
This kind of precision is usually meaningless when you are merely pruning files after n-days. You'll remove the file in today's run or tomorrow's.
Perhaps this explains your observation.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2001 11:28 AM
03-20-2001 11:28 AM
Re: Unix shell script for bash shell #!bin/sh to delete the log files after 3 days.
I use find as well, but i use the following commands.
find /tmp/print -name '*.log' -type f -mtime +5 -exec rm {} \;
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2001 12:20 PM
03-20-2001 12:20 PM
Re: Unix shell script for bash shell #!bin/sh to delete the log files after 3 days.
The above lines work..
I use
find /var/tmp -mtime +30 -exec rm {} \;
However, bash shell is not #!/bin/sh..that is posix shell, bash shell #!/bin/bash..at least default is that on a linux box.