Expect: Difference between revisions
→Reboot Netscaler using Expect
(Page Created) |
|||
(5 intermediate revisions by the same user not shown) | |||
Line 3:
<br />
= Basics =
Installing Expect
=Expect script to ARP Ping=▼
{{UC}}
= Scripts =
▲==Expect script to ARP Ping==
<pre>
#!/usr/bin/expect
set timeout 20
spawn telnet 192.200.200.201
Line 18 ⟶ 28:
send "0\r"
exit
</pre>
Cron Entry
==Expect script to backup Netscaler config==
<pre>
#!/usr/bin/expect
spawn ssh nsroot@10.107.88.78
expect "Password:"
Line 38 ⟶ 48:
send "^C\r"
exit
</pre>
==TCP three-way handshake by hand using expect==▼
▲=TCP three-way handshake by hand using expect=
<pre>
#
set SYN 0x02
set RST 0x04
Line 52 ⟶ 66:
set window 4096
#
set myip 10.10.10.123
set mymac [random mac]
Line 113 ⟶ 127:
}
#
#
# $tcp(ack) and the server's is $tcp(seq) + 1.
#
Line 120 ⟶ 134:
puts Done.
</pre>
== Reboot Netscaler using Expect ==
*This script was tested on NS11.1 build 52.13.nc VPX.
*Recommended to use it under testing environment only as it will NOT perform graceful Netscaler reboot.
*Use it at your own risk:
<pre>
#!/usr/bin/expect
# Netscaler Parameters:
set timeout 10
set nsip 10.107.88.78
set user nsroot
set pass pwd@123
# Login into NetScaler:
spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no $user@$nsip
expect "Password"
send "$pass\n"
expect "Last login:"
# Reboot Command:
send "reboot\n"
expect ":"
send "Y\r"
sleep 1
exit
</pre>
Cron entry to schedule reboot at 2:00AM daily
* 2 * * * /home/test/ns_reboot.sh
<br />
|