-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove2archiv.sh
70 lines (54 loc) · 2.33 KB
/
move2archiv.sh
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
66
67
68
69
#!/bin/bash
# Configuration
suchordner="/Users/bla/Test" # Path to the folder to be searched
archivordner="/Users/bla/TArchiv" # Path to the archive folder
berichtdatei="/Users/bla/Bericht.txt" # Path to the report file
endberichtdatei="/Users/bla/AbschließendenBericht.txt" # Path to the final report file
emailadresse="[email protected]" # E-mail address for the final report
# Check if the archive folder exists. If not, create it.
if [ ! -d "$archivordner" ]; then
mkdir -p "$archivordner"
fi
# Check if the report file exists. If so, delete it.
if [ -f "$berichtdatei" ]; then
rm "$berichtdatei"
fi
# Search the specified folder and its subfolders for files that are older than three years.
while IFS= read -r -d '' file; do
# Retrieve file information
filename="$(basename "$file")"
filesize="$(stat -c%s "$file")"
fileyear="$(date -r "$file" +"%Y")"
filemonth="$(date -r "$file" +"%m")"
# Create report
{
echo "Dateiname: $filename"
echo "Größe: $filesize Bytes"
echo "Verschiebungspfad: $archivordner/$fileyear/$filemonth/$filename"
echo ""
} >> "$berichtdatei"
done < <(find "$suchordner" -type f -mtime +1095 -print0)
# Present the report and ask for confirmation
echo "The report has been generated. Would you like to move the files and send the report? (yes/no)"
read -r confirmation
if [ "$confirmation" != "yes" ]; then
echo "Operation cancelled."
exit
fi
# If confirmed, move the files, create a final report, convert it to a PDF, and send it by e-mail
while IFS= read -r -d '' file; do
# Retrieve file information
filename="$(basename "$file")"
fileyear="$(date -r "$file" +"%Y")"
filemonth="$(date -r "$file" +"%m")"
# Move the file to the archive folder
mkdir -p "$archivordner/$fileyear/$filemonth"
mv "$file" "$archivordner/$fileyear/$filemonth/$filename"
done < <(find "$suchordner" -type f -mtime +1095 -print0)
# Create a final report with the same details as the first report.
cp "$berichtdatei" "$endberichtdatei"
# Convert the final report into a PDF
enscript -p "$endberichtdatei.pdf" "$endberichtdatei"
# Send the final report by e-mail
echo "Hier ist der abschließende Bericht." | mutt -s "Abschließender Bericht" -a "$endberichtdatei.pdf" -- "$emailadresse"
#echo "Hier ist der abschließende Bericht." | mail -s "Abschließender Bericht" -a "$endberichtdatei.pdf" "$emailadresse"