-
Notifications
You must be signed in to change notification settings - Fork 0
/
loops.sh
47 lines (36 loc) · 770 Bytes
/
loops.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
#!/bin/bash
ID=$(id -u)
R="\e[31m"
G="\e[32m"
Y="\e[33m"
N="\e[0m"
TIMESTAMP=$(date +%F-%H:%M:%S)
LOGFILE="/tmp/$0-$TIMESTAMP.log"
echo " Script started execting at $TIMESTAMP " &>> $LOGFILE
VALIDATE(){
if [ $1 -ne 0 ]
then
echo -e "$2 ... $R FAILED $N" &>> $LOGFILE
exit 1
else
echo -e "$2 .... $G SUCCESS $N" &>> $LOGFILE
fi
}
if [ $ID -ne 0 ]
then
echo -e "$R ERROR $N : User is not a root"
exit 1
else
echo -e "$G User is a root one"
fi
for package in $@
do
yum installed $package list &>> $LOGFILE
if [ $? -ne 0]
then
yum install $package -y &>> $LOGFILE
VALIDATE $? "Installation of $package"
else
echo "$package is already installed ...SKIPPING"
fi
done