-
Notifications
You must be signed in to change notification settings - Fork 0
/
adminscript
118 lines (92 loc) · 1.96 KB
/
adminscript
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
112
113
114
115
116
117
118
#!/bin/bash
#Authhor: CHRISTIAN KAM
#Purpose: Basic administration task
#Date: 07/25/2021
#Modification: 07/26/2021
update ()
{
updatedb
if test $? = 0
then echo succefull
else
echo unsuccesfull
fi
}
check()
{
a=`df -h | egrep -v "tmpfs|devtmpfs" | tail -n+2 | awk '{print $5}' | cut -d'%' -f1`
for i in $a
do
if [ $i -ge $max ]
then
echo "Warning – Disk file system has exceeded 20% on :" `df -h | grep $i`
else
echo "you have enough space on : " `df -h | grep $i`
fi
done
}
backup()
{
tar -zcvf $Dest $backup_file >/dev/null 2>&1
if test $? -eq 0
then
echo "Completed backup"
else
echo "failed backup"
fi
}
pingip()
{
for ip in $(cat $IPLIST)
do
ping -c1 $ip &> /dev/null
if [ $? -eq 0 ]
then
echo $ip ping passed
else
echo $ip ping failed
fi
done
}
empty()
{
for i in *
do
if [ -s $i ]; then
echo "$i is a file and size is greater than zero."
else
echo "$i is an empty file and deleting now..."
rm -rf $i
fi
done
}
PS3="PLEASE MAKE YOUR CHOICE: "
select choice in update check_disk backup delete_empty_file pingiplist "QUIT MENU"
do
case $choice in
update) echo "please be a root user before to update the system"
echo "The update will be running in the background"
update &
;;
check_disk) read -p "what is the percentage of space do you want to filter: " max
check
;;
backup)
echo "The backup will be running in the background"
read -p "give the the complete path of the file or directoty you want to backup :" backup_file
read -p "give the full path of the destination of the archive file:" Dest
echo "Started backup"
backup &
;;
delete_empty_file) read -p "WARNING THIS SCRIPT WILL DELETTE ALL EMPTY FILE DO YOU WANT TO CONTINUE (y/n) " answer
if [ "$answer" = "y" ] || [ "$answer" = "Y" ] ;
then
empty
fi
;;
pingiplist) read -p "enter the full path of the ip list :" IPLIST
pingip;;
"QUIT MENU") break ;;
*) echo " Please make a correct choice"
esac
done