Sponsored Content
Top Forums Shell Programming and Scripting rm files in a directory, looping, counting, then exit Post 24794 by peter.herlihy on Wednesday 17th of July 2002 06:36:57 PM
Old 07-17-2002
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.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Counting number of files in a directory

Some simple questions from a simple man. If i wanted to count the number of files contained within a directory, say /tmp would ls -l /tmp ¦ wc -l suffice and will it be accurate? second one: How would i check the number of files with a certain string in the filename, in the same directory. ... (2 Replies)
Discussion started by: iamalex
2 Replies

2. UNIX for Dummies Questions & Answers

Line counting in Directory

I want to count the no of lines for files (.c and .h) present in a directory structure. My code is: #!/bin/bash # Usage: linecount.sh directory_name for file in $(find $1 -name ); do wc -l "$file" >> filecount.txt done Problem is that the directory structure is really big... (3 Replies)
Discussion started by: MobileUser
3 Replies

3. Shell Programming and Scripting

Counting files in a directory that match a pattern

I have 20 files in a direcotry like BARE01_DLY_MKT_YYYYMMDD. The MKT differes for all these files but the remaining syntax remains the same for a particular day. If I am checking for today I need to make sure that there are 20 files that start with BARE01_DLY_MKT_20060720. How can I write a... (31 Replies)
Discussion started by: dsravan
31 Replies

4. Shell Programming and Scripting

Looping through the directory

Hi, I have to write a KSH script to loop through the directory and transfer all the files through FTP. The source machine is the Network shared drive and the files in the directory needs to be FTPied to the UNIX server. For eg. Directory (Datasource) + Directory1 ... (6 Replies)
Discussion started by: mahalakshmi
6 Replies

5. Shell Programming and Scripting

looping thru filenames in a directory

Hi, i am very new to UNIX, i am trying to loop thru the files in a directory. I got the filenames into a variable using $files=`ls` Here $files will contain <filename1> <filename2> <filename3> I want to get one filename at a time and append it to some some text. forexample, ... (1 Reply)
Discussion started by: silas.john
1 Replies

6. Shell Programming and Scripting

running a looping script for all files in directory

I have three different linux command scripts that I run for 20+ files in one directory. it goes like this FIRST SCRIPT: grep 'something' -w file > newfile1 . . . grep 'something -w file > newfile20 then I take all these 'newfileN' and run this: awk 'BEGIN {... (20 Replies)
Discussion started by: labrazil
20 Replies

7. UNIX for Advanced & Expert Users

Counting files in a given directory

Hi all, Need some help counting files... :) I'm trying to count the number of files in a given directory (and subdirectories) which reportedly contains "thousands" of files. I'm using this: ls -R | wc -l However it's been an hour and looks like it's still running; there is no output... (18 Replies)
Discussion started by: verdepollo
18 Replies

8. Shell Programming and Scripting

counting the number of characters in the filename of all files in a directory?

I am trying to display the output of ls and also print the number of characters in EVERY file name. This is what I have so far: #!/bin/sh for x in `ls`; do echo The number of characters in x | wc -m done Any help appreciated (1 Reply)
Discussion started by: LinuxNubBrah
1 Replies

9. Shell Programming and Scripting

Counting the number of files within a directory input by the user

So I have a loop that stated if a directory exists or not. If it does it prints the number of files within that directory. I use this code... result=`(ls -l . | egrep -c '^-')` However, no matter which directory I input, it outputs the number "2" What is wrong here? (4 Replies)
Discussion started by: itech4814
4 Replies

10. Shell Programming and Scripting

Looping through entire directory and count unique values

Hello, I`m a complete newbie to coding, please help with this problem. I have multiple files in a directory, I have to loop through the contents of each file and extract number of unique isoforms in that file. Each file is tab delimited and only the line with the first parent (column 3)... (1 Reply)
Discussion started by: ritakadm
1 Replies
break(1T)						       Tcl Built-In Commands							 break(1T)

__________________________________________________________________________________________________________________________________________________

NAME
break - Abort looping command SYNOPSIS
break _________________________________________________________________ DESCRIPTION
This command is typically invoked inside the body of a looping command such as for or foreach or while. It returns a TCL_BREAK code, which causes a break exception to occur. The exception causes the current script to be aborted out to the innermost containing loop command, which then aborts its execution and returns normally. Break exceptions are also handled in a few other situations, such as the catch com- mand, Tk event bindings, and the outermost scripts of procedure bodies. EXAMPLE
Print a line for each of the integers from 0 to 5: for {set x 0} {$x<10} {incr x} { if {$x > 5} { break } puts "x is $x" } SEE ALSO
catch(1T), continue(1T), for(1T), foreach(1T), return(1T), while(1T) KEYWORDS
abort, break, loop ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +--------------------+-----------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +--------------------+-----------------+ |Availability | SUNWTcl | +--------------------+-----------------+ |Interface Stability | Uncommitted | +--------------------+-----------------+ NOTES
Source for Tcl is available on http://opensolaris.org. Tcl break(1T)
All times are GMT -4. The time now is 12:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy