forked from techforall247/linuxeng_need_shell_scripting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinux_shell_scripting.sh
More file actions
111 lines (71 loc) · 2.89 KB
/
linux_shell_scripting.sh
File metadata and controls
111 lines (71 loc) · 2.89 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
Linux - AWS Cloud Eng Road Map Need Shell Scripting
************************************************
1) File Backup with Datestamp and Send Mail Notification
2) Mysql DB backup Copy to AWS S3 and delete old backup
3) Mysql DB backup local and Send Mail Notification
4) Disk Usage 80% Greater check Send Mail Notification
5) Service UP or down check mail trigger and service status change
6) Memory low check Send Mail Notification
File backup and send mail
*************************
TIME=`date +%b-%d-%y`
FILENAME=backup-$TIME.tar.gz
SRCDIR=/imp-data
DESDIR=/mybackupfolder
tar -cpzf $DESDIR/$FILENAME $SRCDIR
if [ "$?" = "0" ]; then
echo "Backup Process was Successful. A new backup file $FILENAME has been created" | mailx -s "Backup Status Successful" [email protected]
else
echo "Backup Process Failed. Please contact System Administrator" | mailx -s "Backup Status Failed" [email protected]
exit 1
fi
find /imp-data -mindepth 1 -mtime +1 -delete
Mysql DB backup Copy to AWS S3 and delete old backup
****************************************************
#!/bin/bash
FILE=DB_dump_`date +%Y%m%d`.sql
/usr/bin/mysqldump -u root -p password target_db > /backup/$FILE
/bin/gzip /backup/$FILE
/usr/local/bin/aws s3 cp /backup/$FILE.gz s3://targetbucket/SQL/`date +%Y%m%d`/
/bin/rm -rf /backup/$FILE.gz /backup/$FILE
exit 0
Mysql DB backup local and Send Mail Notification
************************************************
#!/bin/bash
filename=live-DB-`date +%Y-%m-%d`.sql
/usr/bin/mysqldump -u root -p password target_db > /backup/$FILE
/usr/bin/zip /backup/DB/$filename.zip /backup/DB/$filename
rm -rf /backup/DB/$filename
find /backup/DB/ -mindepth 1 -mtime +3 -delete
Disk Usage 80% Greater check Send Mail Notification
***************************************************
#!/bin/bash
CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g')
THRESHOLD=80
if [ "$CURRENT" -gt "$THRESHOLD" ] ; then
mail -s 'Disk Space Alert' [email protected]
Your root partition remaining free space is critically low on AOL appserver. Used: $CURRENT%
EOF
fi
Service UP or down check mail trigger
*************************************
#!/bin/bash
UP=$(/etc/init.d/apache2 status | grep running | grep -v not | wc -l);
if [ "$UP" -ne 1 ];
then
echo "webserver is down on AOL.";
else
echo "All is well.";
fi
Shell Script to Check Server Memory
************************************
#!/bin/bash
subject="Server Memory Status Alert"
To="[email protected]"
free=$(free -mt | grep Total | awk '{print $4}')
if [[ "$free" -le 100 ]]; then
echo -e "Warning, server memory is running low!\n\nFree memory: $free MB" | mail -s "$subject" $To
fi
exit 0