- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- A script problem
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
05-22-2005 09:33 PM
05-22-2005 09:33 PM
A script problem
There are some directories under /logs (such as
/logs/bp, /logs/bd, /logs/exec, & etc). The application will generate one log file under these directories every day. It only has to keep the recent 7 days log files. Can you help to provide a script to do it?
Thanks
FJ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2005 09:36 PM
05-22-2005 09:36 PM
Re: A script problem
Use logrotate.
You will get logrotate from http://hpux.connect.org.uk/hppd/hpux/Sysadmin/logrotate-2.5/
Regards,
--Naveej
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2005 09:41 PM
05-22-2005 09:41 PM
Re: A script problem
You may write down a crontab entry which runs once every day at some specified time which will remove all files in the specified directory with file modification date greater than 7 days old.
something like:
#minute hour monthday month weekday command
00 17 * * * find /dir_name -depth -mtime 7 -exec rm -f {} \;
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2005 09:41 PM
05-22-2005 09:41 PM
Re: A script problem
You may write down a crontab entry which runs once every day at some specified time which will remove all files in the specified directory with file modification date greater than 7 days old.
something like:
00 17 * * * find /dir_name -depth -mtime 7 -exec rm -f {} \;
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2005 09:42 PM
05-22-2005 09:42 PM
Re: A script problem
You can cron the file containing command which will remove files older than 7 days. Execute it once everyday through cron.
#find /log -mtime +7 -exec rm {} \;
HTH,
Devender
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2005 10:05 PM
05-22-2005 10:05 PM
Re: A script problem
find /logs/ -mtime 7 -name "*" -exec rm -f {} \;
If you find that log files are having same pattern then use it in -name "" option instead of *
Automate this in cron by,
1. put this command in cron tab directly as,
00 0 * * * find /logs/ -mtime 7 -name "*" -exec rm -f {} \; 1>/dev/null @>&1
2. Else put this in a script file and execute it.
#!/bin/ksh
#test.sh
find /logs/ -mtime 7 -name "*" -exec rm -f {} \;
# chmod 755 /tmp/test.sh
00 0 * * * /tmp/test.sh 1>/dev/null 2>&1
hth.