Update vmcreate1.sh
This commit is contained in:
23
vmcreate1.sh
23
vmcreate1.sh
@@ -12,16 +12,33 @@ show_help()
|
|||||||
|
|
||||||
make_file (){
|
make_file (){
|
||||||
if [ $# -eq 0 ] then
|
if [ $# -eq 0 ] then
|
||||||
do touch hosts.tmp
|
touch hosts.tmp
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
ipcheck "$arg"
|
ipcheck "$arg"
|
||||||
if [ $? -eq 0 ] then
|
if [ $? -eq 0 ] then
|
||||||
echo -n "$arg " >> ./hosts.tmp
|
echo -n "$arg " >> ./hosts.tmp
|
||||||
echo $arg | cut -d '.' -f 3,4 | sed 's/\.//' >> hosts.tmp
|
echo $arg | cut -d '.' -f 3,4 | sed 's/\.//' >> hosts.tmp
|
||||||
|
done
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
ip_check (){
|
function ip_check() {
|
||||||
|
# Функция написана гуглом
|
||||||
|
local ip=$1
|
||||||
|
local stat=1
|
||||||
|
oldIFS=$IFS
|
||||||
|
# Check if the IP matches the general IPv4 pattern
|
||||||
|
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
|
||||||
|
# Split the IP into octets
|
||||||
|
IFS='.' read -r -a octets <<< "$ip"
|
||||||
|
# Check if each octet is within the valid range (0-255)
|
||||||
|
if [[ ${octets[0]} -le 255 && ${octets[1]} -le 255 \
|
||||||
|
&& ${octets[2]} -le 255 && ${octets[3]} -le 255 ]]; then
|
||||||
|
stat=0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
return $stat
|
||||||
|
IFS=$oldIFS
|
||||||
}
|
}
|
||||||
|
|
||||||
hostame_generate(){
|
hostame_generate(){
|
||||||
|
|||||||
Reference in New Issue
Block a user