- 论坛徽章:
- 3
|
回复 1# yejunlon - #!/usr/bin/perl
- use strict;
- use warnings;
- use File::Path 'rmtree';
- my $max_usage = "80";
- sub Free_Space {
- my $max_usage = shift;
- my ( $os, $df, $free_usage, $free ) = $^O;
- if ( $os eq "linux" ) {
- $df = `df -h /opt 2>/dev/null`;
- }
- else {
- $df = `df -g /opt 2>/dev/null`;
- }
- while ( $df =~ /(\d+)%.*?(\/\S*)/g ) {
- $1 > $max_usage ? $free_usage = 1:$free = 1;
- }
- return 1 if defined $free and !defined $free_usage;
- }
- unless (Free_Space("$max_usage") eq "1"){
- rmtree ('/opt/software/',{keep_root => 1,verbose => 1 })
- }
复制代码- 在crontab里添加
- 00 18 * * * /usr/bin/perl /script/cron_rm.pl
复制代码 具体情况 具体改改吧{:3_186:} |
|