From 4f045ffe5aa87adebdcaaf853435077400a79160 Mon Sep 17 00:00:00 2001 From: Dmitry Badovsky Date: Sat, 25 Oct 2025 13:01:17 +0000 Subject: [PATCH] Update vmcreate1.sh --- vmcreate1.sh | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/vmcreate1.sh b/vmcreate1.sh index e27d507..8ee5a0c 100644 --- a/vmcreate1.sh +++ b/vmcreate1.sh @@ -58,11 +58,22 @@ if [ -e $file ]; then touch hosts.tmp echo -n "" > hosts.tmp for line in $(<$file); do - ipcheck (echo $line | cut -d '.' -f 1) - if [ $? -ne 0 ]; then + ip=$(echo $line | cut -d ' ' -f 1) + 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." - - hostcheck (echo $line | cut -d '.' -f 2) + sleep 2 + fi done fi @@ -104,7 +115,9 @@ ipcheck() { } hostcheck (){ - if [[ $1 =~ + local hostname=$1 + local pattern="^[a-zA-Z0-9-]+$" + if [[ "$hostname" =~ $pattern ]]; then return 0; else return 1; fi } #Проверяем ключ