- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to modify this simple 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
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
08-23-2000 04:59 AM
08-23-2000 04:59 AM
Currently I have a directory called /home/shaun/boristest. This contains database files which continually grows. There are approximately 200 plus files in it. As a regular maintnance I have been told by the DBA that he only wants to keep the latest 100 files according to timestamp. The below script3 currently removes 100 files. So if there is 300 files then it will remove 100 and there will still be the latest 200. This is close to being correct but does anyone know how I could modify this simple script to only leave the latest 100 and no more. Your help is greatly appreciated...
drwxrwxrwx 2 shaun adm 4096 Aug 23 08:42 boristest
-rwxrwxr-x 1 shaun adm 263 Aug 22 09:22 script1
-rwxrwxr-x 1 shaun adm 84 Aug 22 09:21 script2
-rwxrwxr-x 1 shaun adm 63 Aug 23 08:41 script3
-rwxrwxrwx 1 shaun adm 87 Aug 22 09:26 test2
#!/usr/bin/sh
cd /home/shaun/boristest
rm `ls -t | tail -100`
Thanks
Shaun Aldrich
SAldrich@chaptersinc.com
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2000 05:02 AM
08-23-2000 05:02 AM
Re: How to modify this simple script???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2000 05:02 AM
08-23-2000 05:02 AM
Re: How to modify this simple script???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2000 05:06 AM
08-23-2000 05:06 AM
Re: How to modify this simple script???
In a previous mail you sent.
Tom's rm `ls -1t | tail +101`
and my rm `ls |grep -v "$(ls -t|head -n100)"`
But didnt pay...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2000 05:13 AM
08-23-2000 05:13 AM
Re: How to modify this simple script???
Thanks a lot for your reply... I couldn't get either of these to work. Here is a copy of your script Victor which I called script2 and the results when I ran it.
#!/usr/bin/sh
cd /home/shaun/boristest
for FILE in 'ls | grep -v "$(ls -t | head -n100)"'
do
rm $FILE
done
$ ./script2
rm: ls non-existent
rm: | non-existent
rm: -v non-existent
rm: "$(ls non-existent
rm: -t non-existent
rm: | non-existent
rm: head non-existent
rm: -n100)" non-existent
Any help is greatly appreciated...
Shaun Aldrich
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2000 05:13 AM
08-23-2000 05:13 AM
Re: How to modify this simple script???
What difference between the 2.
tom: i rm after sorting by time after the 100 first
Victor: i rm all except the result of grep -v
I know my english is hopeless, but I try my best
Victor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2000 05:16 AM
08-23-2000 05:16 AM
Re: How to modify this simple script???
Either script would be good for me if I could get them to work... Thanks for your continous replies...
Shaun Aldrich
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2000 05:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2000 05:17 AM
08-23-2000 05:17 AM
Re: How to modify this simple script???
I'd suggest to modify your script as follows
rm $(ls -1t | awk 'NR>100')
regards
Jaroslaw
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2000 05:29 AM
08-23-2000 05:29 AM
Re: How to modify this simple script???
Thanks again for all of the replies...
Shaun Aldrich
SAldrich@chaptersinc.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2000 05:31 AM
08-23-2000 05:31 AM
Re: How to modify this simple script???
then do find . -name * -exec +100 ls -latr {} \;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2000 05:41 AM
08-23-2000 05:41 AM
Re: How to modify this simple script???
I thought I would try the suggestion that you gave as well and here are the results:
#!/usr/bin/sh
cd /home/shaun/boristest
rm $(ls -1t | awk `NR>100`)
$ ./script4
./script4[4]: NR: not found.
Usage: awk [-F fs][-v Assignment][-f Progfile|Program][Assignment|File] ...
Usage: rm [-Rfir] file ...
Any suggestions on why this failed...
Thanks
Shaun Aldrich
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2000 05:52 AM
08-23-2000 05:52 AM
Re: How to modify this simple script???
I suppose that there is the same mistake as previous.
You should use ' instead of `
Regards
Jaroslaw
Jaroslaw
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2000 05:53 AM
08-23-2000 05:53 AM
Re: How to modify this simple script???
Thanks for your replies to my questions on the forum. I am going to assign points for you right now. Below is the results from what I just tried after your suggestion:
#!/usr/bin/sh
cd /home/shaun/boristest
find . -name * -exec +100 ls -latr {}
$ ./script5
find: missing conjunction
Do you know what it means by missing conjunction? Thanks for your help.
Shaun Aldrich
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2000 05:55 AM
08-23-2000 05:55 AM
Re: How to modify this simple script???
I did use the proper quotes that you recommended. Any other ideas?
Thanks
Shaun Aldrich
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2000 06:10 AM
08-23-2000 06:10 AM
Re: How to modify this simple script???
If I use single quotation mark my command works properly.
[/tmp/jt]# rm $(ls -1t | awk 'NR>1')
[/tmp/jt]# ls
kas.sh
[/tmp/jt]#
Problem arised when I replaced single quotation mark with apostrophe sign:
[/tmp/jt]# rm $(ls -1t | awk `NR>1`)
sh: NR: not found.
Usage: awk [-F fs][-v Assignment][-f Progfile|Program][Assignment|File] ...
Usage: rm [-Rfir] file ...
Regards
Jaroslaw
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2000 06:11 AM
08-23-2000 06:11 AM
Re: How to modify this simple script???
cd /home/shaun/boristest &&
ls -1t *.dbf | tail +101 | xargs rm
The && after the cd means "run the following command only if the cd succeeds" - this script will eventually end up as a cron-job, maybe run by root - if anybody ever moves or removes /home/shaun/boristest the cd will fail, but whithout the && rm will do its job on other files it finds in the current directory - you do not want that to happen - trust me!
The *.dbf is an example only, be just as specific as possible with the names of the files you want to delete - again just as a precaution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2000 06:29 AM
08-23-2000 06:29 AM
Re: How to modify this simple script???
Your solution works great as well!!! If you get a chance can you explain the following line for me:
rm $(ls -1t | awk 'NR>100')
I not sure what awk or NR do... My understanding of scripting needs to get better...
Thanks
Shaun Aldrich
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2000 06:40 AM
08-23-2000 06:40 AM
Re: How to modify this simple script???
According to HP-UX description awk is a "
- pattern-directed scanning and processing language". You can get many details running man awk command.
NR is a special variable which means Number of Records.
regards
Jaroslaw
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2000 07:30 AM
08-23-2000 07:30 AM
Re: How to modify this simple script???
Cheers!