Housekeeping Not Working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Housekeeping Not Working
# 1  
Old 05-26-2011
Housekeeping Not Working

Hi,

I have a .ksh script which finds all the directories older than 84 days and tries to housekeep. Below is the command used

Code:
find * -depth -type d -ctime +84 -exec rm -rf {} \;

The above command lists all the directories ie child and parent directory in descending order which are more than 84 days old

When the script is executed from unix prompt, it does what it was intended for.

But when the same is executed by calling from another .ksh script on a by a oracle batch scheduler it is deleting only the subfolders and not the parent folder.

Can someone throw some light on this.

Last edited by pludi; 05-26-2011 at 07:46 AM..
# 2  
Old 05-26-2011
Files in subdirectories may be newer than the parent dir, so this sounds insufficient and dangerous. Most go by mtime not ctime.

But, if your situation is that the files and subdirs are laid down just after the directory is created, that is OK. Using -depth seems like a waste, and + from {} is faster. Note that if rm returns not zero, because it cannot remove something due to permissions, find stops.

Does your script have a good #!path-to-shell as line 1, and chmod executable? It may be running under a different shell in the scheduler.

Last edited by DGPickett; 05-26-2011 at 11:06 AM..
# 3  
Old 05-26-2011
Hi

the subdirectories and parent directory have the same dates

eg.

Directory D1 - D12, F1, F2, F3, F4, F5

D1 Parent Directory
D12 - Sub-Directory
F1, F2.... - Files in Directory D1

When the command find * -depth -type d -ctime +84 -exec rm -rf {} \; is executed only the Directory D12 is deleted.
The files F1, F2..... and Directory D1 is not removed.


The funny part is when i run the command from command line, it removes D1, D12,Fn. But when this is part of the batch script called from oracle Scheduler its not working as intended and deletes only the sub directory D12.

Last edited by annamalai77; 05-26-2011 at 10:55 AM.. Reason: code tags
# 4  
Old 05-26-2011
Usually, when batch script runs differently, it is the #! (see man execvp()) or permissions. One slip and it runs in the bourne shell as stdin.

Last edited by DGPickett; 05-26-2011 at 11:47 AM..
# 5  
Old 05-26-2011
finds first argument usually is the path where to start the search. You have * as first argument so all entries in your current working directory are passed as argument.
If you want your script to start searching in the current directory use the dot or even better use the absolute path where to start (especially when you execute rm on hits).
Code:
find . -depth -type d -ctime +84 -exec rm -rf {} \;

or
Code:
find /path/to/D1 -depth -type d -ctime +84 -exec rm -rf {} \;


Last edited by cero; 05-26-2011 at 11:46 AM..
# 6  
Old 05-27-2011
Hi Pickett / Cero,

Thanks for your valuable inputs.

Instead of "-depth" clause, can i use -prune which will just list only the parent directory?

Also could it be due to path issues as the script is working fine when i execute it from command line. But the problem arises only when it is called from oracle batch scheduler. The reason for the above doubt is because the path is different between command line and when called from batch scheduler.
# 7  
Old 05-27-2011
By path do you mean the PATH variable or your current working directory? The variable should not have much effect on the result, but your current working directory for sure has when you do not use an absolute path.
GNU find would do something completely different when using -prune ( = do not descend into directories) instead of -depth ( = process directories content first), so it depends on what you try to archive.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

[Tip] Housekeeping Tasks Made Easy - User Home directories and Leftover Files

We have regularly questions about how to create users and user accounts. But regularly user accounts need to be deleted too. It is quite easy to delete the user account itself but usually the HOME directory of the user remains. It is good style to remove these directories but simply deleting... (3 Replies)
Discussion started by: bakunin
3 Replies

2. Shell Programming and Scripting

Disk Space Utilization in HTML format working in one environment and not working on the other

Hi Team, I have written the shell script which returns the result of the disk space filesystems which has crossed the threshold limit in HTML Format. Below mentioned is the script which worked perfectly on QA system. df -h | awk -v host=`hostname` ' BEGIN { print "<table border="4"... (13 Replies)
Discussion started by: Harihsun
13 Replies

3. AIX

Housekeeping null 2>&1 in /dev

Hello, Does anyone know how to housekeeping the null 2>&1 file in /dev? its fill up my system, please help. Thanks :b: (3 Replies)
Discussion started by: only
3 Replies

4. Shell Programming and Scripting

Working web service call not working with curl

Hello, Newbie here, I have a perfectly well working web service call I can issue from chrome (PC Windows 10) and get the results I want (a dimmer being turned on in Fibaro Home Center 2 at level 40) I am not allowed to post urls but the below works with http and :// and... (3 Replies)
Discussion started by: abigbear
3 Replies

5. HP-UX

Problems after filesystem housekeeping

I have noticed that after I clear up the /var filesystem, there are always problems. Does deleting the OLDsyslog.log file cause problems like missing directories and problems accessing crontabs? There were two situations where I faced problems. 1) Deleted OLDsyslog.log (Of course I created... (5 Replies)
Discussion started by: anaigini45
5 Replies

6. Shell Programming and Scripting

Automating pbrun /bin/su not working, whenever manually it is working using putty

I am trying to automate a script where I need to use pbrun /bin/su but for some reason it is not passing thru the pbrun as my code below. . ~/.bash_profile pbrun /bin/su - content c h 1 hpsvn up file path I am executing this from an external .sh file that is pointing to this scripts file... (14 Replies)
Discussion started by: jorgejac
14 Replies

7. Shell Programming and Scripting

Housekeeping script

I have a directory ( eg. /tmp , there are many files in it , I would like to do the houskeeping job , can advise how to develop a script to do the following . 1) if the files are elder than 10 days in this directory , the extension is .txt , then move it to /tmp/tmp-txt , the same , if the files... (2 Replies)
Discussion started by: ust3
2 Replies

8. Shell Programming and Scripting

Script not working in cron but working fine manually

Help. My script is working fine when executed manually but the cron seems not to catch up the command when registered. The script is as follow: #!/bin/sh for file in file_1.txt file_2.txt file_3.txt do awk '{ print "0" }' $file > tmp.tmp mv tmp.tmp $file done And the cron... (2 Replies)
Discussion started by: jasperux
2 Replies

9. Shell Programming and Scripting

housekeeping

hey, I have to write a housekeeping script which would delete any files which are more than 10 days old, the file is named in such a fashion MYTEST20060101_182239.txt MYXML20060112_182879.xml MYEXCEL20060113_546321.xls If the current date is 20060112, then MYTEST20060101_182239.txt will be... (2 Replies)
Discussion started by: mpang_
2 Replies
Login or Register to Ask a Question