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
print-service(1M)					  System Administration Commands					 print-service(1M)

NAME
print-service - select, report, import, export active print service on a system SYNOPSIS
print-service [-s service [-m] | -q | -e file | -i file] DESCRIPTION
The print-service utility manages print service selection, as well as export and import of basic print queue configuration. Only a user root privileges or with the Printer Management profile can change the active print service or import print queue configuration. OPTIONS
The following options are supported: -s service Select the active print service for on a host. service can be one of lp or cups. -m Migrate print queue configuration during print service selection. -q Report the active print service on a host. -e file Export basic print queue configuration to a file. -i file Import basic print queue configuration from a file. EXAMPLES
Example 1 Selecting a Print Service The following command selects the CUPS print service as the active print service on a host. # print-service -s cups Example 2 Reporting the Active Print Service The following command reports the active print service on a host. # print-service -q Example 3 Exporting a Print Queue Configuration The following command exports the print queue configuration from the active print service. # print-service -e /tmp/queues Example 4 Importing a Print Queue Configuration The following command imports the print queue configuration to the active print service. # print-service -i /tmp/queues EXIT STATUS
0 Successful completion. non-zero An error occurred. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWpcu | +-----------------------------+-----------------------------+ |Interface Stability |Obsolete | +-----------------------------+-----------------------------+ SEE ALSO
intro(1), attributes(5) NOTES
The print queue configuration saved and restored during export, import, and migration is limited to queue name and device name. It is likely that further configuration changes will be required before imported or migrated print queues become usable. SunOS 5.11 18 Mar 2008 print-service(1M)
All times are GMT -4. The time now is 03:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy