The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Counting files in one directory matrixtlm UNIX for Dummies Questions & Answers 10 06-15-2007 08:14 PM
Looping through the directory mahalakshmi Shell Programming and Scripting 6 11-23-2006 01:23 AM
Counting files in a directory that match a pattern dsravan Shell Programming and Scripting 31 07-24-2006 12:12 PM
Line counting in Directory MobileUser UNIX for Dummies Questions & Answers 3 02-25-2006 04:15 AM
Counting number of files in a directory iamalex UNIX for Dummies Questions & Answers 2 09-05-2005 11:13 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-16-2002
JporterFDX JporterFDX is offline
Registered User
  
 

Join Date: Jul 2002
Location: Orlando, FL
Posts: 4
rm files in a directory, looping, counting, then exit

I am trying to write a script that will look for a file in a directory, then remove it. I need it to loop until it has removed a certain number of files. Is it better to do a repeat or to list each file in a pattern? Files will be numbered like RAF.01.*, RAF.02.*, etc. Thanks, James
  #2 (permalink)  
Old 07-16-2002
peter.herlihy peter.herlihy is offline
Registered User
  
 

Join Date: Nov 2001
Location: New Zealand
Posts: 333
Need a bit more info here James,

Are you looking to remove all instances of files that follow a certain pattern (i.e. RAF.0*)...or are you looking to remove only some of the files that follow the pattern? Expand on what you mean by a certain number of files.....

Also are all the files going to be in the same directory?

If you want to remove from one directory....and all files that are RAF.0*....then you don't need a script you can just use

Code:
 rm /path/RAF.0*

If you can give us a bit more info....that would help./.
  #3 (permalink)  
Old 07-17-2002
JporterFDX JporterFDX is offline
Registered User
  
 

Join Date: Jul 2002
Location: Orlando, FL
Posts: 4
Thanks Peter. All the files are in the same directory and I will need to delete all files like RAF.* ... but here is the reason i need a script. The files are being created and placed in an archive directory. The files are so big that it causes the machine to run out of space. I need to run the script in the background, so that when each file is created, it removes it. The code that creates the files cannot be changed because the files are needed in the production environment and i am testing in a separate environment where the files are not needed. Thanks again for your help.

James
  #4 (permalink)  
Old 07-17-2002
isacs isacs is offline
Registered User
  
 

Join Date: Mar 2002
Location: Muenster - Germany
Posts: 22
What about a cronjob?

Just enter a line like

0,10,20,30,40,50 * * * * rm /PATH/RAF.*

and every 10 minutes the RAF.* will be deleted.
  #5 (permalink)  
Old 07-17-2002
JporterFDX JporterFDX is offline
Registered User
  
 

Join Date: Jul 2002
Location: Orlando, FL
Posts: 4
cronjob would be the perfect solution, but my Operations Architecture team owns cronjob and they will not approve that request. I am given all the responsibility with none of the power to get it done.

Thanks anyway isacs
  #6 (permalink)  
Old 07-17-2002
peter.herlihy peter.herlihy is offline
Registered User
  
 

Join Date: Nov 2001
Location: New Zealand
Posts: 333
Well hating to suggest a hack method...I will....

You could write a script that continually runs and performs the basic function of a crontab..... i.e.

#!/usr/bin/ksh

while(1)
do
rm /path/RAF.* 2> /dev/null
sleep 600
done

This would run every 600 seconds and remove any files matching the criteria. The Std Error would be thrown away incase there are no files to delete.

You'd need to start this fiel with nohup...so that it ran in the background and wasn't reliant on having a session open. i.e.

nohup script_name &

The issues with this approach are that if you want to stop the process then you'll need to find the PID and kill it. Yuo can do this with:

ps -ef | grep script_name then look for the PID column typically second column. Then

kill 12345 (where 12345 is the process id PID).

The other issue is if the server is shut down - then the script will stop running.

This is NOT the best way and has a number of shortcomings, but if you can't get crontab then maybe it's all you have.

You should enquire about having your own crontab..... in Sun (don't know about HP) it is possible to get crontabs for different users - so you don't have to be root! This would be MUCH more preferable than using this method.
  #7 (permalink)  
Old 07-18-2002
JporterFDX JporterFDX is offline
Registered User
  
 

Join Date: Jul 2002
Location: Orlando, FL
Posts: 4
Thanks Peter, I will try that.

James
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:14 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0