-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathip-extractor.sh
More file actions
executable file
·61 lines (54 loc) · 1.49 KB
/
ip-extractor.sh
File metadata and controls
executable file
·61 lines (54 loc) · 1.49 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
#!/bin/bash
function JobFin {
if [ $1 -eq 2 ]; then
echo ""
echo "Done!"
echo ""
else
echo "Done!"
echo ""
fi
}
function ExtractHosts {
echo "Clearing the hosts file..."
> hosts
echo "The hosts file is now empty."
echo ""
echo "Saving a list of nodes into the hosts file..."
while read LINE; do
echo $LINE | grep -E -o '\b(?!127\.)[0-9]{1,3}(\.[0-9]{1,3}){3}\b' >> hosts
# echo $LINE | grep -E -o '([0-9]{1,3}\.){3}[0-9]{1,3}' >> hosts
printf "▓"
done < load
JobFin 2
echo "Copying the content from load to loadlast"
cat load > loadlast
JobFin 1
echo "Deleting the load file..."
rm load
JobFin 1
echo "Removing possible duplicates..."
sort -u -o hosts hosts
JobFin 1
cat hosts | tr "\n" "," < hosts | sed 's/[,]$//' > hostcom && printf "\n" >> hostcom
cat hosts | tr "\n" " " < hosts | sed 's/[,]$//' > chost && printf "\n" >> chost
}
function CheckHosts {
echo "Checking the content of the hosts file:"
cat hosts
NODES=$(wc -l < hosts)
if [ $NODES -eq 0 ]; then
echo "The hosts file is empty"
elif [ $NODES -eq 1 ]; then
echo "There is 1 node in the hosts file."
elif [ $NODES -ge 2 ]; then
echo "There are $NODES nodes in the hosts file"
fi
}
# Check if 'load' file exists, extract hosts, and check them
if [ -e 'load' ]; then
ExtractHosts
CheckHosts
else
> load && nano load && $0
fi