Skip to content

Commit 5ae0acc

Browse files
add housekeeping job that cleans files those modified more than 365 days
1 parent 6e6c5c6 commit 5ae0acc

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

scripts/housekeeping.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
################################################################################
4+
# Name : housekeeping.sh #
5+
# Author : Ibrahim Musayev #
6+
# Purpose : Clean the directories or files that last modified more than #
7+
# 365 days ago on two servers. #
8+
# #
9+
# History : 22.12.22 Ibrahim Musayev, creation #
10+
################################################################################
11+
12+
hostname=$(hostname -s)
13+
14+
if [[ ${hostname:1:1} == "p" && ${hostname:9:10} == "01" ]]; then
15+
# Find all directories those are modified more than 365 days in the mcs directory in main env server 1
16+
mcs_dir="/opt/prai/mcs"
17+
18+
for folder in $(find $mcs_dir -type d ! -path $mcs_dir -not -name "????" 2>/dev/null)
19+
do
20+
# Check if the directory was last modified more than 365 days ago
21+
if [[ $(find $folder -maxdepth 1 -type d -mtime +365 2>/dev/null) ]]
22+
then
23+
# Delete the contents of the directory if it meets the criteria
24+
echo "Target folder: $folder" && rm -r $folder/* && find $mcs_dir -type d -empty -delete
25+
fi
26+
done
27+
28+
elif [[ ${hostname:1:1} == "p" && ${hostname:9:10} == "02" ]]; then
29+
# Find all files those are modified more than 365 days in the projects/mcs_data directory in main env server 2
30+
mcs_data="/var/opt/"
31+
acq_data="/var/opt/ACQ_DATA"
32+
iss_data="/var/opt/ISS_DATA"
33+
input_data="1_DATA_INPUT"
34+
output_data="4_DATA_OUTPUT"
35+
36+
find $acq_data/{$input_data,$output_data} -type f -mtime +365 -delete && find $acq_data/{$input_data,$output_data} -type d -empty -delete
37+
find $iss_data/{$input_data,$output_data} -type f -mtime +365 -delete && find $iss_data/{$input_data,$output_data} -type d -empty -delete
38+
39+
echo "Target folders cleaned: $acq_data/{$input_data,$output_data}"
40+
echo "Target folders cleaned: $iss_data/{$input_data,$output_data}"
41+
42+
fi

0 commit comments

Comments
 (0)