Leser: 1
|< 1 2 >| | 16 Einträge, 2 Seiten |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use Date::Calc qw(Delta_Days);
my ($dir_date,$directory) = "";
my ($mday,$mon,$year) = (localtime(time-60*60*24*7*8))[3..5]; #get the current time minus 8 weeks (ca. 2 months)
#convert the strings into the right format
$year += 1900;
$mon += 1;
#if the length of the string mon and mday are only 1, add a leading 0
if (length($mon) == 1)
{
$mon="0$mon";
}
if(length($mday) == 1)
{
$mday="0$mday";
}
#get all the directory's from the startup_config
@configs = `ls -l /home/confbackup/startup_configs/`;
foreach (@configs)
{
if (!($_ =~ /total/))
{
$length = @informations = split (/\s/,$_); #split each line and get also the number of arguments splitted
$dir_date = $informations[$length-3]; #get the create date from the directory
$directory = $informations[$length-1]; #get the directory name
$directory = "/home/confbackup/startup_configs/".$directory; #add an absolute path to the directory
($dir_year,$dir_mon,$dir_mday) = split (/\-/,$dir_date);
#get the difference between the create_date of the directory and the date 8 weeks ago
$Dd = Delta_Days($dir_year,$dir_mon,$dir_mday,
$year,$mon,$mday);
#if the difference is positive, the directory is older than 8 weeks
if ($Dd > 0)
{
opendir(DIR,"$directory");
@files=readdir(DIR);
closedir(DIR);
#delete all files from the directory
foreach(@files)
{
unlink("$directory/$_");
}
#delete the directory itself
rmdir("$directory");
}
}
}
QuoteEs löscht einfach alle alle directory die älter als 8 Wochen sind.
1
2
3
4
5
opendir (DIR, $directory) or die "Error: couldn't open dir '$directory': $!\n"
...
unlink ("$directory/$_") or warn "Error: couldn't unlink file '$directory/$_': $!\n";
...
rmdir ($directory) or warn "Error: couldn't unlink '$directory': $!\n";
@configs = `ls -l /home/confbackup/startup_configs/`;
1
2
3
4
5
6
my $command = "ls -l /home/confbackup/startup_configs/";
unless (open(CMD, "$command |")) {
die "Error in executing command: $!\n";
}
@configs = <CMD>; chomp(@confix);
close(CMD);
$Dd = Delta_Days($dir_year,$dir_mon,$dir_mday,$year,$mon,$mday);
my $last_modify = -M $file;
Quote`Wird das script nicht ausgeführt oder bricht es ab?
|< 1 2 >| | 16 Einträge, 2 Seiten |