Tuesday, August 2, 2016

My quick scripts

Run below script on PAGENT after bringing up dot1x sessions using eapse

for {set count 1} {$count <= 222} {incr count} {
   dce stop
   dce clear all
   dce g0/1
   dce add client
   dce expand 79
   dce delay-start 500
   after 5000
   dce start
   after 1800000
}

#################################################################################

Run below script on DHCP server after bring up all dot1x sessions:

for {set count 1} {$count <= 400} {incr count} {
      puts "\nIteration - $count\n"
        puts [exec clear ip dhcp bind *]
        after 1000
        ios_config "ip dhcp excluded-address 23.23.0.0 23.23.99.255"
        after 1000
        puts [exec clear ip dhcp bind *]
        puts "\n#### \nSleep 500 seconds  ####\n"
        after 500000
        puts "\nBindings should be above 23.23.99.255\n"
        after 1000
        puts [exec sh ip dhcp bind | c 23.23]
        after 5000
        puts [exec sh ip dhcp bind]
        after 50000
        puts [exec clear ip dhcp bind *]
        after 1000
        ios_config "ip dhcp excluded-address 23.23.100.0 23.23.199.255"
        after 1000
        ios_config "no ip dhcp excluded-address 23.23.0.0 23.23.99.255"
        puts "\n#### \nSleep 500 seconds  ####\n"
        after 500000
        puts "\nBindings should be below 23.23.100.0\n"
        after 1000
        puts [exec sh ip dhcp bind | c 23.23]
        after 50000
        puts [exec sh ip dhcp bind]
        after 5000
        ios_config "no ip dhcp excluded-address 23.23.100.0 23.23.199.255"
        after 1000
        puts "End of iteration - $count"
}

#########################################################################################

1. Run the command "./UIHC-cont" to collect Auth Manager and EPM memory data every 5 minutes
2. Run "./UIHC-mem-report-generator" to dump the collected data

Below files form a set:

UIHC-ssh
UIHC-cont
UIHC-mem-usage        
UIHC-mem-report-generator

#############################################################################################

Run below scripts on free radius server to collect stats periodically:


root@FR-121:~# ls UIHC*
UIHC_collect_stats       UIHC-cont         UIHC-mem-report-generator  UIHC-ssh
UIHC_collect_stats_cont  UIHC_health_data  UIHC-mem-usage

UIHC:
root@FR-121:~#
##############################################################################################

root@FR-121:~# cat UIHC-ssh

sshpass -p "welcome123" ssh -o StrictHostKeyChecking=no client1@9.27.156.11 << EOF


show clock

term shell

sleep 300

show process memory detailed process iosd sorted | i EPM.*MAIN|Auth.*Manager|Free

EOF
root@FR-121:~#

###############################################################################################

root@FR-121:~# cat UIHC-cont
#!/bin/bash
a=1
while [ $a -gt 0 ]
do
  /root/UIHC-ssh >> UIHC-mem-usage
done
root@FR-121:~#

##############################################################################################


root@FR-121:~# more UIHC-mem-report-generator
rm auth_mgr
rm processor_mem
rm mem_report
cat UIHC-mem-usage | grep "Auth Manager" | cut -c 34-42 | nl >> auth_mgr
cat UIHC-mem-usage | grep "Processor" | cut -c 40-50 >> processor_mem
paste auth_mgr processor_mem | column -s $'\t' -t >> mem_report
cat mem_report
root@FR-121:~#
##############################################################################################

Below files form a set:

UIHC_collect_stats
UIHC_collect_stats_cont
UIHC_health_data

##############################################################################################

root@FR-121:~# cat UIHC_collect_stats
sshpass -p "welcome123" ssh -o StrictHostKeyChecking=no client1@9.27.156.11 << EOF

######################  BEGIN ITERATION  #####################

show clock

term shell

term exec prompt timestamp

show clock

show ver

show region

show auth sess | i count

show dot1x all count

show ip dhcp snooping bind

show processes memory sorted

show processes memory detailed process iosd sorted

show processes memory detailed process iosd maps

show memory detailed process iosd allocating-process total

show redundancy

show redundancy switchover history

show aaa memory detailed

show aaa memory stats all

show mem deb leaks detailed process iosd

show auth attrlist

sleep 3600

##################  END OF ITERATION  ##############################
EOF
root@FR-121:~#

###########################################################################################

root@FR-121:~# cat UIHC_collect_stats_cont
#!/bin/bash
a=1
while [ $a -gt 0 ]
do
  /root/UIHC_collect_stats >> UIHC_health_data
done

root@FR-121:~#

############################################################################################
copy_mem_report script to be run on 10.104.99.167 to fetch the mem_report from 9.27.15.121

#!/bin/bash
a=1
while [ $a -gt 0 ]
do
  scp root@9.27.15.121:/root/mem_report .
  sleep 300
done

Run as shown below by running Cygwin terminal as administrator:

admin@NOVA-PC ~
$ cd "C:\Users\admin\Desktop\POLARIS\UIHC"

admin@NOVA-PC /cygdrive/c/Users/admin/Desktop/POLARIS/UIHC
$ ./copy_mem_report
mem_report                                    100% 3596     3.5KB/s   00:01
mem_report                                    100% 3596     3.5KB/s   00:00
mem_report                                    100% 3596     3.5KB/s   00:00
mem_report                                    100% 3596     3.5KB/s   00:00
mem_report                                    100% 3596     3.5KB/s   00:00
mem_report                                    100% 3596     3.5KB/s   00:00
mem_report                                    100% 3596     3.5KB/s   00:00
mem_report                                    100% 3596     3.5KB/s   00:00
mem_report                                    100% 3596     3.5KB/s   00:00
mem_report                                    100% 3596     3.5KB/s   00:00
mem_report                                    100% 3596     3.5KB/s   00:00
mem_report                                    100% 3596     3.5KB/s   00:00
mem_report                                    100% 3596     3.5KB/s   00:00


############################################################################################################