-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautomation.sh
60 lines (44 loc) · 1.43 KB
/
automation.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
#!/bin/bash
# Variables used
name="shubham"
s3_bucket="upgrad-shubham"
apt update -y
if [[ apache2 != $(apt --get-selections apache2 | awk '{print $1}') ]]; then
#statements
apt install apache2 -y
fi
running=$(systemctl status apache2 | grep active | awk '{print $3}' | tr -d '()')
if [[ running != ${running} ]]; then
#statements
systemctl start apache2
fi
enabled=$(systemctl is-enabled apache2 | grep "enabled")
if [[ enabled != ${enabled} ]]; then
#statements
systemctl enable apache2
fi
# Creating file name
timestamp=$(date '+%d%m%Y-%H%M%S')
cd /var/log/apache2
tar -cf /tmp/${name}-httpd-logs-${timestamp}.tar *.log
if [[ -f /tmp/${name}-httpd-logs-${timestamp}.tar ]]; then
#statement
aws s3 cp /tmp/${name}-httpd-logs-${timestamp}.tar s3://${s3_bucket}/${name}-httpd-logs-${timestamp}.tar
fi
docfile="/var/www/html"
# Check if inventory file exists
if [[ ! -f ${docfile}/inventory.html ]]; then
#statement
echo -e 'Log Type\t-\tTime Created\t-\tType\t-\tSize' > ${docfile}/inventory.html
fi
# Inserting Logs into the file
if [[ -f ${docfile}/inventory.html ]]; then
#statement
size=$(du -h /tmp/${name}-httpd-logs-${timestamp}.tar | awk '{print $1}')
echo -e "httpd-logs\t-\t${timestamp}\t-\ttar\t-\t${size}" >> ${docfile}/inventory.html
fi
# a cron job that runs service daily
if [[ ! -f /etc/cron.d/automation ]]; then
#statement
echo " @daily root /root/Automatio_Project/automation.sh" >> /etc/cron.d/automation
fi