- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Need shell script.....
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-21-2005 09:37 PM
04-21-2005 09:37 PM
I am not good at shell programming...
I need to add in crontab a script to delete the old directory logfile.
For example: I just want to keep for the most 3 days current logfile directory:
drwxr-x--- 2 am users 96 Apr 17 12:00 20050410/
drwxr-x--- 2 am users 96 Apr 17 12:00 20050411/
drwxr-x--- 2 am users 96 Apr 18 12:00 20050412/
drwxr-x--- 2 am users 96 Apr 19 12:00 20050413/
drwxr-x--- 2 am users 8192 Apr 20 12:00 20050414/
drwxr-x--- 2 am users 8192 Apr 16 00:16 20050415/
drwxr-x--- 2 am users 8192 Apr 21 12:00 20050416/
drwxr-x--- 2 am users 8192 Apr 18 00:05 20050417/
drwxr-x--- 2 am users 8192 Apr 19 00:05 20050418/
drwxr-x--- 2 am users 8192 Apr 20 00:05 20050419/
drwxr-x--- 2 am users 8192 Apr 21 00:05 20050420/
drwxr-x--- 2 am users 8192 Apr 22 00:05 20050421/
In this example I just keep for these days: 21, 20, 19 and the older directory will be delete at 00:00 (by crontab)
Any helps will be much appreciated!
HoangChiCong
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2005 09:43 PM
04-21-2005 09:43 PM
Re: Need shell script.....
Remove only empty directories ?
Robert-Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2005 09:47 PM
04-21-2005 09:47 PM
Re: Need shell script.....
a one liner will do:
# find
regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2005 09:55 PM
04-21-2005 09:55 PM
Re: Need shell script.....
I prefer using modification time above access time (Joseph's reply). If the directories are not empty, the -f option is necessary.
The syntax then would be:
find
Hope it helps you,
Renarios
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2005 10:08 PM
04-21-2005 10:08 PM
Re: Need shell script.....
Of course, it is not empty! It is logfile!
To Joseph Loo:
The full path: /home/ams/coms/log/
I tried with you command but nothing deleted!
Any idea?
Thanks!
Regard,
HoangChiCong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2005 10:12 PM
04-21-2005 10:12 PM
Re: Need shell script.....
But never empty because it contain all of the logfile as my last post!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2005 10:29 PM
04-21-2005 10:29 PM
Re: Need shell script.....
Mark Syder (like the drink but spelt different)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2005 10:33 PM
04-21-2005 10:33 PM
Re: Need shell script.....
search first
# find /home/ams/coms/log/ -type d -mtime +2 -exec ls -ld {} ;
before doing this:
# find /home/ams/coms/log/ -type d -mtime +2 -exec rm -R {} ;
regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2005 10:39 PM
04-21-2005 10:39 PM
Re: Need shell script.....
It runs but as not I want!
Here are directory after run that command (with mtime):
drwxr-x--- 2 am users 8192 Apr 20 12:00 20050414/
drwxr-x--- 2 am users 8192 Apr 21 12:00 20050416/
drwxr-x--- 2 am users 8192 Apr 20 00:05 20050419/
drwxr-x--- 2 am users 8192 Apr 21 00:05 20050420/
drwxr-x--- 2 am users 8192 Apr 22 00:05 20050421/
thanks
HoangChiCong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2005 10:45 PM
04-21-2005 10:45 PM
Re: Need shell script.....
I would suggest changing the mtime +2 to mtime +3 (but I expect that will have to wait till Monday to confirm it's worked).
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2005 10:46 PM
04-21-2005 10:46 PM
Re: Need shell script.....
Find files modified between 3 and 8 days!!
# find /home/ams/coms/log/ -type d -mtime +3 -mtime +8 -exec ls -ld {} ;
# find /home/ams/coms/log/ -type d -mtime +3 -mtime +8 -exec rm -R {} ;
Regards,
Naveej
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2005 10:47 PM
04-21-2005 10:47 PM
Re: Need shell script.....
Find files modified between 3 and 8 days!!
# find /home/ams/coms/log/ -type d -mtime +3 -mtime -8 -exec ls -ld {} ;
# find /home/ams/coms/log/ -type d -mtime +3 -mtime -8 -exec rm -R {} ;
Regards,
Naveej
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2005 11:54 PM
04-21-2005 11:54 PM
Re: Need shell script.....
Download the caljd.sh (aka A. Clay Stephenson's Date Hammer) script from below link to /usr/local/bin
http://mirrors.develooper.com/hpux/#Contrib
Create a small script.
#!/usr/bin/ksh
CALJD=/usr/local/bin/caljd.sh
# set date 3 days back
RMDATE=$($CALJD -Y -s $($CALJD -p 3))
# remove old log directory
/usr/bin/rm -r /home/ams/coms/log/$RMDATE
The first time you will need to delete the older directories yourself.
Hope this helps,
Robert-Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2005 01:32 AM
04-22-2005 01:32 AM
Re: Need shell script.....
#!/bin/sh
TODAY=`date +%Y%m%d`
DAY3=`expr $TODAY - 2`
for LOG in `ls /home/ams/coms/log`
do
if [ `expr $LOG \< $DAY3` = 1 ]
then
echo $LOG
rm -rf $LOG
fi
done
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2005 03:55 PM
04-22-2005 03:55 PM
Re: Need shell script.....
Today is weekend so that I can not check for all of your script at home.
I will answer on next monday.
Later for points....
Thanks
HoangChiCOng
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2005 12:10 AM
04-24-2005 12:10 AM
Re: Need shell script.....
I have already changed mtime to +3 but that is not I expect.
To Naveej:
Had error in your command line:"find: -exec not terminated with ';'"
To Robert-Jan Goossens:
Could you attached that shell file? Silly but I can not find that file (caljd.sh)
To Geoff Wild:
It seems that just delete all of the directory, I have tried to change to :
"rm -Rf $LOG" but the same!
Any idea?
Thanks
HoangChiCong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2005 04:19 AM
04-24-2005 04:19 AM
Solution- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2005 04:37 AM
04-24-2005 04:37 AM
Re: Need shell script.....
#!/bin/sh
TODAY=`date +%Y%m%d`
DAY3=`expr $TODAY - 2`
for LOG in `ls /home/ams/coms/log`
do
if [ `expr $LOG \< $DAY3` = 1 ]
then
echo $LOG
rm -rf /home/ams/coms/log/$LOG
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2005 07:00 PM
04-24-2005 07:00 PM
Re: Need shell script.....
May be I have to learn shell programming. :):):)
Can anyone show me some usefull document that teaching shell programming? (Anyway, for beginer is suitable for me - I thinks so :(:( ).
Thanks again.
Regard,
HoangChiCong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2005 07:07 PM
04-24-2005 07:07 PM
Re: Need shell script.....
how about this doc:
http://docs.hp.com/en/B2355-90046/index.html
regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2005 07:23 PM
04-24-2005 07:23 PM
Re: Need shell script.....
-mtime n
True if the file modification time subtracted
from the initialization time is n-1 to n
multiples of 24 h. The initialization time
shall be a time between the invocation of the
find utility and the first access by that
invocation of the find utility to any file
specified in its path operands.
PME.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2005 12:35 AM
04-25-2005 12:35 AM
Re: Need shell script.....
http://www.unixguide.net/unix/sedoneliner.shtml
http://pandonia.canberra.edu.au/OS/l3_1.html
http://www.shelldorado.com/shelltips/script_programmer.html
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2005 07:46 PM
04-25-2005 07:46 PM
Re: Need shell script.....
Have a good time.
Regard,
HoangChiCong