1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#!/bin/bash
# blog: http://lizhenliang.blog.51cto.com
function
check_ip() {
IP=$1
VALID_CHECK=$(
echo
$IP|
awk
-F.
'$1<=255&&$2<=255&&$3<=255&&$4<=255{print "yes"}'
)
if
echo
$IP|
grep
-E
"^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$"
>
/dev/null
;
then
if
[ ${VALID_CHECK:-no} ==
"yes"
];
then
echo
"IP $IP available."
else
echo
"IP $IP not available!"
fi
else
echo
"IP format error!"
fi
}
# Example
check_ip 192.168.1.1
check_ip 256.1.1.1
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#!/bin/bash
# blog: http://lizhenliang.blog.51cto.com
function
check_ip() {
IP=$1
if
[[ $IP =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]];
then
FIELD1=$(
echo
$IP|
cut
-d. -f1)
FIELD2=$(
echo
$IP|
cut
-d. -f2)
FIELD3=$(
echo
$IP|
cut
-d. -f3)
FIELD4=$(
echo
$IP|
cut
-d. -f4)
if
[ $FIELD1 -
le
255 -a $FIELD2 -
le
255 -a $FIELD3 -
le
255 -a $FIELD4 -
le
255 ];
then
echo
"IP $IP available."
else
echo
"IP $IP not available!"
fi
else
echo
"IP format error!"
fi
}
# Example
check_ip 192.168.1.1
check_ip 256.1.1.1
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#!/bin/bash
# blog: http://lizhenliang.blog.51cto.com
function
check_ip() {
local
IP=$1
VALID_CHECK=$(
echo
$IP|
awk
-F.
'$1<=255&&$2<=255&&$3<=255&&$4<=255{print "yes"}'
)
if
echo
$IP|
grep
-E
"^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$"
>
/dev/null
;
then
if
[ $VALID_CHECK ==
"yes"
];
then
echo
"IP $IP available!"
return
0
else
echo
"IP $IP not available!"
return
1
fi
else
echo
"IP format error!"
return
1
fi
}
while
true
;
do
read
-p
"Please enter IP: "
IP
check_ip $IP
[ $? -
eq
0 ] &&
break
done
|
#!/bin/sh
check_ip() {
local IP=$1
VALID_CHECK=$(echo $IP|awk -F. '$1<=255&&$2<=255&&$3<=255&&$4<=255{print "yes"}')
if echo $IP|grep -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" >/dev/null; then
if [ $VALID_CHECK == "yes" ]; then
echo "IP $IP available!"
return 0
else
echo "IP $IP not available!"
return 1
fi
else
echo "IP format error!"
return 1
fi
}
break_con() {
if [ $1 -eq 0 ];then
break
else
continue
fi
}
while :
do
if read -p "Do you want to install deploy-platform now [Y/N]:"
then
case $REPLY in
Y|y) #Y
while :
do
read -p "please input the repo_ip of deploy-platform eg[10.0.0.10]:"
echo "repo_ip=$REPLY"
repo_ip=$REPLY
check_ip $repo_ip
break_con $?
done
echo -e "\n start install deploy-platform now \n detail in /var/log/puppet_installdeploy.log \n"
sed -i -e 's/$repo_ip =.*$/$repo_ip = '$REPLY'/' /var/tmp/openstackha/deploy/manifests/init.pp
puppet apply -l /root/puppet_installdeploy.log --modulepath /var/tmp/openstackha/puppet/modules/ /var/tmp/openstackha/deploy/manifests/init.pp -d
break
;;
N|n) #N
echo -e "\n Not install deploy-platform! \n"
break
;;
*) #input error repeat
echo -e "\n input parameter error !! \n"
continue
esac
fi
done
check_ip() {
local IP=$1
VALID_CHECK=$(echo $IP|awk -F. '$1<=255&&$2<=255&&$3<=255&&$4<=255{print "yes"}')
if echo $IP|grep -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" >/dev/null; then
if [ $VALID_CHECK == "yes" ]; then
echo "IP $IP available!"
return 0
else
echo "IP $IP not available!"
return 1
fi
else
echo "IP format error!"
return 1
fi
}
break_con() {
if [ $1 -eq 0 ];then
break
else
continue
fi
}
while :
do
if read -p "Do you want to install deploy-platform now [Y/N]:"
then
case $REPLY in
Y|y) #Y
while :
do
read -p "please input the repo_ip of deploy-platform eg[10.0.0.10]:"
echo "repo_ip=$REPLY"
repo_ip=$REPLY
check_ip $repo_ip
break_con $?
done
echo -e "\n start install deploy-platform now \n detail in /var/log/puppet_installdeploy.log \n"
sed -i -e 's/$repo_ip =.*$/$repo_ip = '$REPLY'/' /var/tmp/openstackha/deploy/manifests/init.pp
puppet apply -l /root/puppet_installdeploy.log --modulepath /var/tmp/openstackha/puppet/modules/ /var/tmp/openstackha/deploy/manifests/init.pp -d
break
;;
N|n) #N
echo -e "\n Not install deploy-platform! \n"
break
;;
*) #input error repeat
echo -e "\n input parameter error !! \n"
continue
esac
fi
done