Sponsored Content
Top Forums Shell Programming and Scripting Perl Script to find the disk usage and to delete the files which is consuming more space Post 302654183 by arunkarthick on Monday 11th of June 2012 10:48:54 AM
Old 06-11-2012
Perl Script to find the disk usage and to delete the files which is consuming more space

Hi All,

I have written a script to check the file system usage and to delete the files which is consuming more space.Please check whether the script is corrcet

Code:
#Script Starts here 
#!/usr/local/bin/perl
#Program to find the disk space and to delete the older files
#Checks the type of OS here
$OS = `uname -a | awk '{print $1}'`;
print ("The Operating System is $OS");
if ($OS == SunOS ) {
   
    print ("Enter the filesystem related to SUN \n");
    $FILESYSTEM = <STDIN>;
     
    $DF = `df -sk $FILESYSTEM | awk '{print $3,$4,$5}' | awk '{if($3>50)print $3}'`;
    
    print ("The file system $ FILESYSTEM usage is $DF \n");
    while ($DF > 50){
    
    print ("The file system $FILESYSTEM reached its maximum capacity $DF and request you to clear the space /n");
    print ("Please enter "YES" if you want to delete the files which is consuming more space /n");
    print ("Please enter "NO" if you want to proceed as it is /n");
 
    $OPTION = <STDIN>;
    given ($OPTION) {
    when ("YES")  { `find $FILESYSTEM -size +5242880c -size -10485760c 2>/dev/null -print | xargs -i rm -i {}` }
                  { Print "The file system which is consuming more space has been removed \n" }
                  break;
    when ("NO") { exit (); }
 
    }
    }
    } elsif ($OS == HP-UX) {
    print ("Please enter the filesystem related to HP-UX \n");
    $FILESYSTEM1 = <STDIN>;
    $DF1 = `bdf $FILESYSTEM1 | awk -F " " '{ print $3,$4,$5 }' | xargs -i cut -f 3 -d " " {}`;
    print ("The file system $ FILESYSTEM usage is $DF \n");
    
    while ($DF1 > 50){
    print ("The file system $FILESYSTEM1 usage is $DF1 and request you to clear the space \n");
    }
#End Of Script
    }


Last edited by pludi; 06-11-2012 at 12:32 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

finding disk space usage

How would I go about finding the about of disk space occupied by a certain directory? For example, /u1/cvera => 530 MB Thanks =) (3 Replies)
Discussion started by: cvera8
3 Replies

2. UNIX for Dummies Questions & Answers

how to determine the disk space usage

how can we determine the disk space used by a certain directory? (1 Reply)
Discussion started by: gfhgfnhhn
1 Replies

3. Shell Programming and Scripting

Perl script to check free disk space

hello, I have to check the free space on the disk that would work both on Windows and Unix platform e.g on C: \ for Windows and / on Unix. I could use Unix command 'df ' ( my windows system has Unix emulator cygwin and could run 'df ' as well). But I'd like not to rely on system command but... (1 Reply)
Discussion started by: susja
1 Replies

4. Shell Programming and Scripting

Shell script delete log files from folder & subfolders on space usage

Hi, I am trying to write a shell script to delete logs generate by db when space in the folder reaches 70%. i am getting space values from db, find the files at OS and remove them by using a cron job runs every 5minutes. I have to keep the latest 5 files at any time, my problem is that log files... (3 Replies)
Discussion started by: saha
3 Replies

5. UNIX for Dummies Questions & Answers

How to find a file whick is consuming larger disk space in file system

Hello, Can anybody please tell me the command to find out the filesystem or a file which is consuming larger disk space sing i want to find out the file and want to compress it please help me out any help would be appreciated (6 Replies)
Discussion started by: lokeshpashine
6 Replies

6. Shell Programming and Scripting

script to monitor disk space usage

Some times my disk space is used upto 100% due to the application logs . So this script is to monitor the disk space usage and wall message to the users about the disk space usage if it exceeds the limit set in the script. Here for example the limit is set to 80%. This job is added in cron to... (2 Replies)
Discussion started by: amitranjansahu
2 Replies

7. Shell Programming and Scripting

Disk Usage - Space Used

Hi all, FreeBSD7.1 @ sh. In a backup script I am trying to get the blocks used by the backup once completed. I am using the function: #!/bin/sh spaceused() { du -d 0 "${1}" | awk -F"+" '{ print $1 } } to return the blocks used of said directory and contents. Via. command line... (7 Replies)
Discussion started by: Festus Hagen
7 Replies

8. UNIX Desktop Questions & Answers

Issue with disk space usage

Issue with disk space usage I have the following line in my "df -h" output: Filesystem Size Used Avail Capacity Mounted on /dev/ad4s1a 496M 495M -39M 109% / What is the issue with having 9% excess utilisation? How can I find out what this partition is... (2 Replies)
Discussion started by: figaro
2 Replies

9. Shell Programming and Scripting

Need Generic command for disk space usage

Given this directory /web I need to get the current usage (in %) on Linux and Unix both using the same command on bash shell ? The command i tried was working on Unix (solaris) but does not filter the desired same value when run of Linux. My command df -h /web | awk '{print $5}' | sed -n... (5 Replies)
Discussion started by: mohtashims
5 Replies

10. HP-UX

Files consuming more space in HP-UX

Hi, Could you please provide OS command to find large files in size MB and GB... under specific directory in HP-UX? Regards, Maddy (4 Replies)
Discussion started by: Maddy123
4 Replies
UNAME(1)							   User Commands							  UNAME(1)

NAME
uname - print system information SYNOPSIS
uname [OPTION]... DESCRIPTION
Print certain system information. With no OPTION, same as -s. -a, --all print all information, in the following order, except omit -p and -i if unknown: -s, --kernel-name print the kernel name -n, --nodename print the network node hostname -r, --kernel-release print the kernel release -v, --kernel-version print the kernel version -m, --machine print the machine hardware name -p, --processor print the processor type or "unknown" -i, --hardware-platform print the hardware platform or "unknown" -o, --operating-system print the operating system --help display this help and exit --version output version information and exit AUTHOR
Written by David MacKenzie. REPORTING BUGS
Report uname bugs to bug-coreutils@gnu.org GNU coreutils home page: <http://www.gnu.org/software/coreutils/> General help using GNU software: <http://www.gnu.org/gethelp/> COPYRIGHT
Copyright (C) 2009 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. SEE ALSO
arch(1), uname(2) The full documentation for uname is maintained as a Texinfo manual. If the info and uname programs are properly installed at your site, the command info coreutils 'uname invocation' should give you access to the complete manual. GNU coreutils 7.1 July 2010 UNAME(1)
All times are GMT -4. The time now is 07:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy