Last active
March 30, 2017 10:59
-
-
Save JohnPreston/b22b4bde6ee399c58c4dbfac15d9e5a7 to your computer and use it in GitHub Desktop.
add secondary ip after primary has been set
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ $# -ne 1 ]; then | |
echo "Usage: addip.sh IPv4CIDR" | |
exit 1 | |
fi | |
IPCIDR=$1 | |
export PATH=$PATH:/usr/bin:/sbin | |
cat /dev/null > /tmp/ipset.result | |
echo "INIT STARTED - `date '+%Y-%m-%d %H:%M:%S'`" >> /tmp/ipset.result | |
while [ 42 ]; do | |
MAIN_IP_IS_SET=`ip addr sh eth0 | grep inet | grep brd | wc -l` | |
if [ $MAIN_IP_IS_SET -eq 1 ]; then | |
break | |
fi | |
sleep 1 | |
done | |
echo "MAIN IP IS SET AT `date '+%Y-%m-%d %H:%M:%S'`" >> /tmp/ipset.result | |
echo "WATITING 10 seconds" >> /tmp/ipset.result | |
sleep 10 | |
i=0; | |
while [ $i -ne 20 ] ; do | |
/sbin/ip addr add $IPCIDR dev eth0 2>&1 >> /tmp/ipset.log | |
IP_IS_SET=`ip addr sh eth0 | grep $IPCIDR | wc -l` | |
if [ $IP_IS_SET -eq 1 ]; then | |
echo "`date '+%Y-%m-%d %H:%M:%S'` - IP IS SET on eth0" >> /tmp/ipset.result | |
/sbin/ip addr sh eth0 2>&1 > /tmp/ipset.proof | |
break | |
else | |
echo "`date '+%Y-%m-%d %H:%M:%S'` - IP IS NOT SET on eth0" >> /tmp/ipset.result | |
fi | |
i=$((i+1)) | |
sleep 0.5; | |
done | |
chmod 644 /tmp/ipset* | |
IP_IS_SET=`ip addr sh eth0 | grep $IPCIDR | wc -l` | |
if [ $IP_IS_SET -eq 0 ]; then exit 1; else exit 0; fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment