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
Such a script is really dangerous and it should contain code to stop it running on any Operating System Partition and anywhere which legitimately has large files. Taking the filesystem as a user-supplied parameter is asking for trouble.
The script comment says "Program to find the disk space and to delete the older files". There is no code in the script which looks at the age of the files, but there is code to look at the size of individual files.
I can't vet Perl code, but the unix commands look iffy.
This find command has a lot wrong with it.
It needs -xdev to confine the scope to one filesystem.
It needs -type f to just look at files.
There is a Shell redirect in the middle of the arguments.
The size range needs escaped brackets or only the second value will be taken into account.
The size range is very strange. It equates to 5 Megabytes to 10 Megabytes.
Test the script with an echo not a direct rm command !
The delimiter between fields is not a single space, it is multiple spaces.
You probably mean something like:
I believe that both Operating Systems have df -Pk and could produce the same format of output.
Last edited by methyl; 06-11-2012 at 06:03 PM..
Reason: typo
Some one please help me, i'm receiving the following error when i execute this script
./diskusgae.pl: line 7: use: command not found
./diskusgae.pl: line 9: use: command not found
./diskusgae.pl: line 11: use: command not found
./diskusgae.pl: line 17: =: command not found
./diskusgae.pl: line 19: syntax error near unexpected token `"The Operating System is $OS \n"'
./diskusgae.pl: line 19: `print ("The Operating System is $OS \n");'
bash-3.00$ vi diskusgae.pl
"diskusgae.pl" 73 lines, 1613 characters
Please help me as i need to implement this in my pre-prod environment.
When i try to execute the below command from command line I'm getting the required output.
But when i try to execute the same in script i'm receving the below exception
Please guide me.
---------- Post updated 06-13-12 at 08:24 PM ---------- Previous update was 06-12-12 at 11:15 PM ----------
Hi All,
Could some one guide me
When i try to execute the below command from command line I'm getting the required output.
Code:
df -h $FILESYSTEM -exec | grep -v "Filesystem" | sed -e "s/%//g"|awk '{print $5}'
But when i try to execute the same in script i'm receving the below exception
Code:
bash-2.05$ ./diskusage.plThe Operating System is SunOSEnter the filesystem related to SUN/u001sh: syntax error at line 2: `|' unexpected
Please guide me.
Last edited by Franklin52; 06-13-2012 at 03:45 AM..
Reason: Please use code tags for data and code samples
I think that this needs someone who knows Perl. The error is coming from unix Shell but the main program is Perl. Perhaps the call from Perl to unix Shell contains an error which is corrupting the command?
Depending on which version of Sunos this is, the sh command may be the old Bourne Shell and you may need to use nawk not awk.
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)
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)
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)
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)
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)
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)
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)