Update vmcreate1.sh

This commit is contained in:
2025-10-25 13:01:17 +00:00
parent 7289c257e2
commit 4f045ffe5a

View File

@@ -58,11 +58,22 @@ if [ -e $file ]; then
touch hosts.tmp touch hosts.tmp
echo -n "" > hosts.tmp echo -n "" > hosts.tmp
for line in $(<$file); do for line in $(<$file); do
ipcheck (echo $line | cut -d '.' -f 1) ip=$(echo $line | cut -d ' ' -f 1)
if [ $? -ne 0 ]; then hostname=$(echo $line | cut -d ' ' -f 2)
ipcheck "$ip"
if [ $? -eq 0 ]; then
hostcheck "$hostname"
if [ $? -eq 0 ];
then
echo $line >> hosts.tmp
else
echo "Hostname `$hostname` is not valid. Should contain only letters, numbers and dash. Skipping this line."
sleep 2
fi
else
echo "$ip is not a valid IPv4 address (10.10.*.*). Skipping this line." echo "$ip is not a valid IPv4 address (10.10.*.*). Skipping this line."
sleep 2
hostcheck (echo $line | cut -d '.' -f 2) fi
done done
fi fi
@@ -104,7 +115,9 @@ ipcheck() {
} }
hostcheck (){ hostcheck (){
if [[ $1 =~ local hostname=$1
local pattern="^[a-zA-Z0-9-]+$"
if [[ "$hostname" =~ $pattern ]]; then return 0; else return 1; fi
} }
#Проверяем ключ #Проверяем ключ