Script for deleting files and directories when the file system reaches the threshold
Hi
Can someone assist in writing a script.
I have a filesystem named /sybase in my aix lpar.
When this filesystem becomes 94% full all the files and directories under /sybase/logs should be deleted immediately.
This script should be run by cron as often, as you think is necessary (every hour, day?). If you want it to run every hour, just copy it into /etc/cron.hourly, if that exists on your system. If not, then make an entry in the crontab. Make sure the script is executable.
Hi Jayan Jay
The command you have given works fine. Thank you so much
@ Mirni : I saved the content you gave as script.ksh
When I execute it gives the below error:
Hi Jayan Jay
The command you have given works fine.
Actually, jayan's one liner may not work correctly on some systems -- it may clear the directory tree even if the use is low. With GNU df, the header contains '%' sign and so you have two lines there:
Awk in jayan's command will process both of these lines. Regardless of the use% in the second line (the actual record), the first line will always be matched. That's because the fifth field of the first line, stripped of the '%', will satisfy the if condition:
is always true in awk's language. That is because the integer 94 is automatically converted to a string, and then compared to "Use".
As for my code, it seems that the variable 'use' is empty. Try to echo 'use' variable before the if statement. What does this print?
Last edited by mirni; 01-17-2012 at 09:27 AM..
Reason: removed offensive word "bug"
@mirni, i am using SunOS 5.9 and when firing df -h , it wont show Use% in fifth column ..
Hence the header of df -h might vary from OS to OS and dont come to a conclusion that the one liner has a bug ..
If your OS doesnt support that feature, below is the one liner will suit your match.
One more in nawk ..
I didn't mean to offend you -- I appreciate you being here helping others. I only wanted to point out a potential pitfall. Although it may work with your version of df (and perhaps the OP's also), it didn't with mine on GNU/Linux system.
Remember there may be many people viewing this post trying to find a solution to their problem on their variety of *nix platforms...
I reformulated my previous post a little bit.
Peace,
mirni
I am trying to accomplish following tasks in my KSH script:
Run a sql script on multiple $ORACLE_SID at once
Sends an alert only if the threshold > 2 for any of the $ORACLE_SID
Please advice as to how I can approach this!!
Thanks in advance! (1 Reply)
Hello All,
I need immediate help in creating shell script to call archivebkup.ksh script when archive file system capacity reaches threshold value or 60%
Need to identify the unique file system that reaches threshold value.
ex:
capacity
... (4 Replies)
Hi,
Seems like I need help again with a problem:
I want to delete all files from my lets say "Music" Directory inkluding all of the subfolders
except for .mp3 and .MP3 files.
I tried it with globalignoring mp3 files, finding and deleting all other files, which
resulted in all files... (3 Replies)
Hi All,
New to unix. Here is the problem. Running a script that extracts data from hyperion essbase and generates a file in unix. This script fails most of the times with a very low success rate. The data has increased a lot in the last few months resulting in the file being more than 2 gb.
... (2 Replies)
Hello out there,
I want to setup a crontab feature to remove temporary pdf files from sub directories that are older than 30 days. I want to presevere the directory structer though. I got this far for a command. Will this remove the pdf's in subdirectories or just directly under the pdf folder? If... (6 Replies)
Hi Friends,
I am new to this , I am working on AIX system and my scenario is to retrive the files from remote system and remove the files from the remote system after retreving files. I can able to retrieve the files but Can't remove files in remote system. Please check my code and help me out... (3 Replies)
Hello Friends,
Im trying to delete empty files in subdirectories with a command. I can find them checking only one directory in each step and then show them with my command like below moreover i could not add removing part:
ls -l */* | awk '{if ($5==0) printf "%3s %2d %s... (5 Replies)
Hi there,
I have a some directories containing web files that are old, and I need to remove them. I know that there might be sym links and hyperlinks pointing to these old directories. If that's the case, then I'll have to fix the links before deleting these old directories to avoid broken... (4 Replies)
I searched the forum, but I don't think I was able to find exactly what I'm looking for.
Is there a command in shell where I can delete a particular string from every file it occurs in (where the file is named the same, but sits in different directories)?
Example: Within the directory I am... (5 Replies)
Hi
My problem is i have to remove some log files in specific named directories on a regular basis using shell scripts. What i want my shell script to do is i give the shell script some listing of directories from which to delete all log files recursively.
Can anyone please help me.
... (2 Replies)