-
Notifications
You must be signed in to change notification settings - Fork 3
/
check.pl
59 lines (48 loc) · 1.33 KB
/
check.pl
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
#!/usr/bin/perl
#Directory Monitor
my $initialTime = `date +"%Y-%m-%d %T"`;
my @initialFiles = `ls -1 --file-type | grep -v '/' | sed s/@\$//`;
my @initialDirs = `ls -l | grep ^d | cut -d' ' -f9`;
chomp @initialFiles;
chomp @initialDirs;
#initializing hashes
my %files = ();
my %dirs = ();
my $date;
#getting the current date of the files
foreach (@initialFiles){
$date = `stat -c%y $_ | cut -d. -f1`;
$files{ $_ } = $date;
}
#getting the current date of the dirs
foreach (@initialDirs){
$date = `stat -c%y $_ | cut -d. -f1`;
$dirs{ $_ } = $date;
}
#continually checks to see if files have changes
while(1){
my @currentFiles = `ls -1 --file-type | grep -v '/' | sed s/@\$//`;
my @currentDirs = `ls -l | grep ^d | cut -d' ' -f9`;
chomp @currentFiles;
chomp @currentDirs;
#making new hash for current files/dir
#initializing hashes
my %newFiles = ();
my %newDirs = ();
#getting the current date of the files
foreach (@currentFiles){
$date = `stat -c%y $_ | cut -d. -f1`;
$newFiles{ $_ } = $date;
}
#getting the current date of the dirs
foreach (@currentDirs){
$date = `stat -c%y $_ | cut -d. -f1`;
$newDirs{ $_ } = $date;
}
#at this point we should check if
#the arrays of hashes are the same
#alert if there's a change
#log the file
#sleeping
sleep(2);
}