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 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
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):>,6,00d000ee27fc,3,vlan 0,tun 0,vsd 0,route 0
7(1800):<-,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):>,17,0003baf1f792,11,vlan 0,tun 0,vsd 0,route 0
6(0800):<-,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):>,6,00000c07ac00,3,vlan 0,tun 0,vsd 0,route 4
3(0010):<-,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):>,17,000000000000,4,vlan 0,tun 0,vsd 0,route 0
6(0600):<-,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):>,6,00d000ee27fc,3,vlan 0,tun 0,vsd 0,route 0
7(1800):<-,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):>,6,0001d7376082,14,vlan 0,tun 0,vsd 0,route 0
6(1800):<-,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):>,17,00000c07ac00,3,vlan 0,tun 0,vsd 0,route 4
3(0010):<-,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):>,17,0001d73c7082,14,vlan 0,tun 0,vsd 0,route 0
6(0800):<-,17,00000c07ac00,3,vlan 0,tun 0,vsd 0,route 4
Total 8 sessions shown
customer_firewall-> Connection to customer_firewall closed. 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
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 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., 2022: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho