Last active
November 12, 2020 07:14
-
-
Save chenchun/c044f16f111084004f458e91ccb6e3cd to your computer and use it in GitHub Desktop.
bash expect, close nf_conntrack
This file contains hidden or 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
#!/usr/bin/expect -f | |
set node [lindex $argv 0] | |
set passwd [lindex $argv 1] | |
set timeout 30 | |
spawn ssh root@$node | |
expect { | |
"yes/no" { send "yes\r";exp_continue } | |
"password:" { send "$passwd\r" } | |
} | |
expect "*#" | |
send "iptables -F && iptables -t nat -F && iptables -X && iptables -t nat -X \ | |
&& sed -i 's~KUBE_PROXY~KUBE_PROXY--N~g' /usr/local/gaiaStack_monitor/gaiaStackMetricsScript/gaiastack-monitor/gaiaLocalMonitor.cfg \ | |
&& modprobe -r -v xt_conntrack ipt_MASQUERADE iptable_nat nf_conntrack_ipv4 xt_nat \ | |
&& cat > /etc/modprobe.d/disable-nfconntrack.conf <<EOF | |
alias nf_conntrack off | |
alias nf_conntrack_ipv4 off | |
alias xt_comment off | |
alias nf_defrag_ipv4 off | |
alias nf_nat_ipv4 off | |
alias nf_nat off | |
alias iptable_nat off | |
alias xt_nat off | |
alias xt_statistic off | |
alias xt_nat off | |
alias ipt_MASQUERADE off | |
alias xt_recent off | |
alias xt_mark off | |
alias xt_comment off | |
alias xt_addrtype off | |
EOF | |
\r" | |
expect "#" | |
send "exit\r" |
This file contains hidden or 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
#!/usr/bin/expect -f | |
set node [lindex $argv 0] | |
set passwd [lindex $argv 1] | |
set timeout 30 | |
spawn ssh root@$node | |
expect { | |
"yes/no" { send "yes\r";exp_continue } | |
"password:" { send "$passwd\r" } | |
} | |
expect "*#" | |
send "mkdir -p /tmp/testfile\r" | |
expect "#" | |
send "exit\r" |
This file contains hidden or 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
#!/usr/bin/expect -f | |
set node [lindex $argv 0] | |
set passwd [lindex $argv 1] | |
set timeout 30 | |
spawn ssh root@$node | |
expect { | |
"yes/no" { send "yes\r";exp_continue } | |
"password:" { send "$passwd\r" } | |
} | |
interact |
This file contains hidden or 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
# Set up various other variables here ($user, $password) | |
# Get the list of hosts, one per line ##### | |
set f [open "host.txt"] | |
set hosts [split [read $f] "\n"] | |
close $f | |
# Get the commands to run, one per line | |
set f [open "commands.txt"] | |
set commands [split [read $f] "\n"] | |
close $f | |
# Iterate over the hosts | |
foreach host $hosts { | |
spawn ssh $user@host | |
expect "password:" | |
send "$password\r" | |
# Iterate over the commands | |
foreach cmd $commands { | |
expect "% " | |
send "$cmd\r" | |
} | |
# Tidy up | |
expect "% " | |
send "exit\r" | |
expect eof | |
close | |
} |
This file contains hidden or 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
#!/usr/bin/expect -f | |
# scp $passwd file [email protected]:~/ | |
# scp $passwd -r file [email protected]:~/ | |
set passwd [lindex $argv 0] | |
set args [lrange $argv 1 end] | |
set timeout 30 | |
spawn scp {*}$args | |
expect { | |
"yes/no" { send "yes\r";exp_continue } | |
"password:" { send "$passwd\r" } | |
} | |
expect "*$" | |
This file contains hidden or 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
#!/usr/bin/expect -f | |
set node [lindex $argv 0] | |
set passwd [lindex $argv 1] | |
set args [lrange $argv 2 end] | |
set timeout 30 | |
spawn ssh root@$node {*}$args | |
expect { | |
"yes/no" { send "yes\r";exp_continue } | |
"password:" { send "$passwd\r" } | |
} | |
interact | |
# batch.sh, node.txt format: ip password | |
IFS=$'\n'; for i in `cat node.txt`; do ip=$(echo $i | awk '{print $1}'); pass=$(echo $i | awk '{print $2}'); echo ip=$ip pass=$pass; ./ssh.sh $ip $pass "$@"; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment