Last active
December 1, 2016 20:25
-
-
Save theeye-io/88de26ca1b16ce190de037dd2684ee0f to your computer and use it in GitHub Desktop.
Bash / Expect script for add a node into an old F5 LoadBalancer's pool.
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/bash | |
which expect > /dev/null | |
if [ "$?" -eq "1" ];then echo FAILURE | |
else | |
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ];then echo FAILURE Some var is undefined set PASS $1 POOL $2 ipAndPort $3;exit;fi | |
PASS=$1 | |
POOL=$2 | |
ipAndPort=$3 | |
tempFile=/tmp/resultado | |
#Variable | |
scriptName=addNode.exp | |
expectCommand="ssh theeye@10.2.2.2 'modify ltm pool \$pool members add { $ipAndPort }'" | |
# | |
rm $tempFile | |
cat <<EOF > $scriptName | |
#!/usr/bin/expect -f | |
set force_conservative 0 ; | |
if {\$force_conservative} { | |
set send_slow {1 .1} | |
proc send {ignore arg} { | |
sleep .1 | |
exp_send -s -- \$arg | |
} | |
} | |
set password [lindex \$argv 0]; | |
set pool [lindex \$argv 1]; | |
set timeout -1 | |
spawn \$env(SHELL) | |
match_max 100000 | |
expect "$ " | |
send -- "$expectCommand" | |
sleep 1 | |
send -- "\r" | |
expect -exact "\r | |
Password: " | |
send -- "\$password\r" | |
expect "$ " | |
send -- "exit\r" | |
expect eof | |
EOF | |
chmod +x $scriptName | |
state="success" | |
expect ./$scriptName $PASS $POOL | |
echo $state | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment