Hallo ich habe hier ein Perl Script was auch so funktioniert, aber leider nicht im cronjob.
Ist vielleicht nicht das beste, aber es tut seinen dienst. Ich weiß nur nicht warum es nicht läuft wenn es als Cronjob deklariert ist?
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");
}
}
}
Es löscht einfach alle alle directory die älter als 8 Wochen sind.
Hoffe mir kann jemand helfen.