Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
output is being iterated ?

Posted by doublea1535 (doublea1535), 2 August 2006
For this script that I am writing, I am spawning ssh to a firewall to connect and grab output. Then I run commands against this list to filter the list into what I want. What I am seeing is that at the end of the processing, the exit command received from the firewall is being repeated.

Here is my script in action :

aaron@server ~/bin/expect : mkuniquelist customer_firewall
spawn ssh admin@customer_firewall
admin@customer_firewall's password:
Remote Management Console
customer_firewall-> get session
alloc 8/max 32064, alloc failed 0, mcast alloc 0, di alloc failed 0
id 10418/s**,vsys 0,flag 04000000/0000/01,policy 50028,time 180, dip 0
6(9801):64.78.178.102/32805->206.71.73.30/4353,6,00d000ee27fc,3,vlan 0,tun 0,vsd 0,route 0
7(1800):64.78.178.102/32805<-172.16.222.30/4353,6,0001d73c7082,14,vlan 0,tun 0,vsd 0,route 12
id 11056/s**,vsys 0,flag 04000000/0000/01,policy 50014,time 5, dip 0
5(8801):10.169.50.38/123->216.87.64.20/123,17,0003baf1f792,11,vlan 0,tun 0,vsd 0,route 0
6(0800):206.71.73.8/123<-216.87.64.20/123,17,00000c07ac00,3,vlan 0,tun 0,vsd 0,route 4
id 12141/s**,vsys 0,flag 00000040/0080/21,policy 320002,time 180, dip 0
6(0601):216.87.64.3/53195->206.71.64.52/22,6,00000c07ac00,3,vlan 0,tun 0,vsd 0,route 4
3(0010):216.87.64.3/53195<-206.71.64.52/22,6,000000000000,4,vlan 0,tun 0,vsd 0,route 0
id 19847/s**,vsys 0,flag 00000040/0080/21,policy 50005,time 6, dip 0
3(0011):206.71.64.52/2568->64.78.224.54/514,17,000000000000,4,vlan 0,tun 0,vsd 0,route 0
6(0600):206.71.64.52/2568<-64.78.224.54/514,17,00000c07ac00,3,vlan 0,tun 0,vsd 0,route 4
id 26688/s**,vsys 0,flag 04000000/0000/01,policy 50027,time 179, dip 0
6(9801):64.78.178.102/52299->206.71.73.31/4353,6,00d000ee27fc,3,vlan 0,tun 0,vsd 0,route 0
7(1800):64.78.178.102/52299<-172.16.222.31/4353,6,0001d7376082,14,vlan 0,tun 0,vsd 0,route 12
id 29188/s**,vsys 0,flag 04000000/0000/01,policy 50029,time 179, dip 0
7(9801):172.16.222.31/35810->64.78.178.102/4353,6,0001d7376082,14,vlan 0,tun 0,vsd 0,route 0
6(1800):206.71.73.31/35810<-64.78.178.102/4353,6,00000c07ac00,3,vlan 0,tun 0,vsd 0,route 4
id 29752/s**,vsys 0,flag 00000040/0080/21,policy 320002,time 3, dip 0
6(0601):64.78.224.54/57248->206.71.64.52/161,17,00000c07ac00,3,vlan 0,tun 0,vsd 0,route 4
3(0010):64.78.224.54/57248<-206.71.64.52/161,17,000000000000,4,vlan 0,tun 0,vsd 0,route 0
id 31564/s**,vsys 0,flag 04000000/0000/01,policy 50029,time 3, dip 0
7(8801):10.101.0.200/123->216.87.64.20/123,17,0001d73c7082,14,vlan 0,tun 0,vsd 0,route 0
6(0800):206.71.73.4/123<-216.87.64.20/123,17,00000c07ac00,3,vlan 0,tun 0,vsd 0,route 4
Total 8 sessions shown
customer_firewall-> Connection to customer_firewall closed.
64.78.178.102 10.169.50.38 206.71.73.8 216.87.64.3 206.71.64.52 172.16.222.31 206.71.73.31 64.78.224.54 10.101.0.200 206.71.73.4 customer_firewall-> Connection to customer_firewall closed.


Notice the string "Connection to customer_firewall closed." is received at the end of when I disconnect from the firewall, and then it shows up again at the very end of the output.

Posted by doublea1535 (doublea1535), 2 August 2006
aaron@server ~/bin/expect : cat mkuniquelist
#!/usr/local/bin/expect
set name $argv
set logfile $name.session
set password password

;# connect to the firewall and get the session info
exec echo -n > $logfile
spawn ssh admin@$name
expect "assword"
send "$password\r"
expect "$name"
log_file $logfile
send "get session\r"
expect "$name"
send "exit\r"
expect "Connection to $name closed."

;# create the main (source) list, this list can contain duplicates
set mainlist [exec grep - $logfile | sed "s/^.*://" | sed {s/\/.*$//}]
;# create the final (sort) list, this list will only contain unique entries, initiate to null
set sortlist ""
;# flag used to signal a duplicate entry; initialize to 0 (0 = not duplicate)
set duplicate 0
;# start foreach against the main list, create a new variable from the current element
foreach element $mainlist {
       set mainlist_entry $element
       ;# run if statement to see the sort list is null, if so (this is first run) then add current mainlist element
       if { "$sortlist" == "" } {
               set sortlist $mainlist_entry
       } else {
               ;# if the sort list is not empty, then compare the current mainlist entry
               ;# against all of the entries already in the source list
               foreach element $sortlist {
                       set sortlist_entry $element
                       ;# if the current mainlist entry is equal to the current sortlist entry...
                       ;# then set duplcate to 1
                       if { "$mainlist_entry" == "$sortlist_entry" } {
                               set duplicate 1
                       }
               }
               ;# now the entire sortlist has been compared to this mainlist entry
               ;# check to see if duplicate is set, if not than add this entry to the sortlist
               if { "$duplicate" == "0" } {
                       set sortlist "$sortlist $mainlist_entry"
               }
       }
       ;# if this was a duplicate, then we just ignore (drop) it, either way reset duplicate
       set duplicate 0
}
;# this will echo out the sortlist to display only unique entries
puts $sortlist

Posted by doublea1535 (doublea1535), 2 August 2006
Nevermind everyone, it was because I was getting extra lines in my $sortlist that I wasn't expecting.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho