Update vmcreate1.sh
This commit is contained in:
15
vmcreate1.sh
15
vmcreate1.sh
@@ -9,6 +9,7 @@ show_help()
|
||||
echo "-k - embed custom public key or create new if 'pub_keyfile' not specified"
|
||||
echo "\nIf file not specified, script will use arguments as a list of IP addresses."
|
||||
echo "In this case Hostname will be inherited from 2 last IP octets. Example for 10.10.35.20: 'vm035020'."
|
||||
echo "IP address should be 10.10.*.*"
|
||||
|
||||
|
||||
# Обрабатываем опции
|
||||
@@ -34,16 +35,20 @@ if [ $# -eq 0 && -v $file && ! -f $file ]; then
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ $# -ne 0 && -v file ]; then show_help; fi
|
||||
# Если заданы аргументы И файл
|
||||
if [ $# -ne 0 && -v file ]; then echo "Please enter file OR arguments. Use '-f' flag for help"; exit 0; fi
|
||||
|
||||
# Если заданы аргументы, то создаем временный файл
|
||||
if [ $# -ne 0 ] then
|
||||
touch hosts.tmp
|
||||
for arg in "$@"; do
|
||||
ipcheck "$arg"
|
||||
if [ $? -eq 0 ] then
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo -n "$arg " >> ./hosts.tmp
|
||||
echo $arg | cut -d '.' -f 3,4 | sed 's/\.//' >> hosts.tmp
|
||||
else
|
||||
echo "Argument $arg is not valid IP address (10.10.*.*). Using next argument."
|
||||
fi
|
||||
done
|
||||
fi
|
||||
@@ -58,8 +63,8 @@ function ip_check() {
|
||||
# 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
|
||||
if [[ ${octets[0]} -eq 10 && ${octets[1]} -eq 10 \
|
||||
&& ${octets[2]} -le 254 && ${octets[3]} -le 254 ]]; then
|
||||
stat=0
|
||||
fi
|
||||
fi
|
||||
@@ -67,7 +72,7 @@ function ip_check() {
|
||||
IFS=$oldIFS
|
||||
}
|
||||
|
||||
hostame_generate(){
|
||||
function hostame_generate(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user