Neelkanth's Expect Script Notes

#################################################################################
Neelkanth's expect notes
#################################################################################


##################################################################
How to tell bash that the line continues on the next line
##################################################################
The character is a backslash \
From the bash manual:
The backslash character ‘\’ may be used to remove any special 
meaning for the next character read and for line continuation.

################################################################
How to execute linux system shell commands in expect
################################################################
system "ls -lrt"

###########################################################
how to access member of an array:
###########################################################
set pwd_list {
          admin123
          admiaskdfhasgdfkasdghfkasdhgn123
          admin123
}
set prev_password [lindex $pwd_list 0]
puts "prev_password $prev_password"


###########################################################
command line arguments
###########################################################
$ cat  print_cmdline_args.exp
#!/usr/bin/expect
puts 'argv0 : [lindex $argv 0]';
puts 'argv1 : [lindex $argv 1]';


puts "\nCommand line argument password: argv0 : [lindex $argv 0]   reboot count: argv1 : [lindex $argv 1]"
# pass command line argument
set password [lindex $argv 0]
if {$password  == ""} {
    puts "enter password as 1st argument to the script"
    send "quit\r"
    exit
}

set REBOOT_COUNT [lindex $argv 1]
if {$REBOOT_COUNT  == ""} {
    puts "enter reboot count as 2nd argument to the script"
    send "quit\r"
    exit
}

############################################################
ctrl + c in expect
############################################################
send \x03

############################################################
# send CTRL + ]
############################################################
send “35\r”

##########################################################################################
#  Why send "[xyz\r]" should be in send "\[xyz\r\]"
##########################################################################################
    -re "[sudo] password for subhasish:" {send "$password\r"}
    In Tcl (and hence in expect) the square brackets are the syntax
    for command substitution (like backticks in the shell). So you
    either need to escape the brackets or use different quotes that
    prevent various expansions:

    -re {[sudo] password for subhasish:} {send "$password\r"}
    That brings up a different issue: are you expecting to see these
    exact characters? Because you're instructing expect to treat that as
    a regular expression, and square brackets in a regular expression means
    a character class, so it will match a single character,
    either a 's', 'u', 'd' or 'o'. So what you probably need is this:
    -re {\[sudo\] password for subhasish:} {send "$password\r"}
###########################################################################################



############################################################
How to use multiple conditions in expect scripting
############################################################
spawn ssh remotessh@$ADMIN_IP_ADDRESS
expect "*password" {send "admin123\r"}
# If ssh login is successful, test case is failed
sleep 2
expect {
    "remotessh completed login" {
                                 terminate_telnet_ssh_session ssh
                                 sleep 1
                                }
    "Permission denied, please try again" {
                                        send “35\r”
                                        # If ssh login fails, test case is failed
                                        send ""
                                          }
}




If the program terminates, there can be no more output forthcoming. 
expect recognizes this. Specifically, expect recognizes the closing of
 the connection to the spawned process. This closing is referred to as end of file or more succinctly, eof.[20


######################################################################
How to fetch the output string into a variable after expect
######################################################################
When matching a pattern, 
any matching and previously unmatched output is saved in the variable expect_out(buffer). 
The matched output may be found in expect_out(0,string).

If a regular expression with sub-expressions was used, then the matching sub-expressions 
(up to 9 in total) may be found in expect_out(1,string) through expect_out(1,string).


  expect "=="
  set  a  $expect_out(buffer)
  set  b  $expect_out(0,string)
  #The easiest way is to use regexp -all -inline to select and return all words.
  set c [regexp -all -inline {\S+} $a]

  set res [lindex $c 2]



Sample expect scripting programs that cover various concepts

#############################################################################################################
#                              AUTOMATION IS FOR EVERYONE --- Neelkanth                                     #
#############################################################################################################



#!/usr/bin/expect -f

##############################################################################################################
#                                           Variables:
##############################################################################################################
# set expect timeout to 60 secs
set   timeout                                   60
set   CLI_PROMPT                                12345
set   ADMIN_USER_NAME                           admin
set   ADMIN_PASSWORD                            admin123
set   PRE_CLI_PROMPT                            asdf
set   NEW_PROMPT                                zxcv

#############################################################################################################
#                          Create a array of passwords here
#############################################################################################################

set pwd_list {
          admin123
          1
          fasdfsf
          werqwerqwer
          213421342134214213
          23412341234213333333333
          ddddddddddddddddd
          a3453345
          admin123
}


#################################################################################################################
#                                       PROCEDURES / FUNCTIONS
#################################################################################################################

##############################################################################
# Procedure: terminate_session_from_RG_shell_prompt
#
# Arguments: none
##############################################################################
proc terminate_session_from_RG_shell_prompt {} {
# Send special ^] to telnet so we can tell telnet to quit.
    expect "# " { send “35\r” }
    expect "telnet>" { send "q\r\r" }
    expect eof
#  You should also, either call "wait" (block) for process to exit or "wait -nowait"
#  (don't block waiting) for process exit.
#  Without "wait", expect may sever the connection to the process prematurely, this
#  can cause the creation zombies in some rare cases. If the application did not get our
#  signal earlier (the EOF from close), or if the process doesn't interpret EOF as an exit
#  status then it may also continue running and your script would be none the wiser.
#  With wait, we ensure we don't forget about the process until it cleans up and exits.
#  <  in short, wait is to clean up zombies >
        wait
        sleep 1
}


##############################################################################
# Procedure: terminate_session_from_RG_CLI_PROMPT
#
# Arguments: none
##############################################################################
proc terminate_session_from_RG_CLI_PROMPT {} {
# Send special ^] to telnet so we can tell telnet to quit.
    global CLI_PROMPT

    expect $CLI_PROMPT { send “35\r” }
    expect "telnet>" { send "q\r\r" }
    expect eof
#############################################################################################
#  You should also, either call "wait" (block) for process to exit or "wait -nowait"        #
#  (don't block waiting) for process exit.                                                  #
#  Without "wait", expect may sever the connection to the process prematurely, this         #
#  can cause the creation zombies in some rare cases. If the application did not get our    #
#  signal earlier (the EOF from close), or if the process doesn't interpret EOF as an exit  #
#  status then it may also continue running and your script would be none the wiser.        #
#  With wait, we ensure we don't forget about the process until it cleans up and exits.     #
#  <  in short, wait is to clean up zombies >                                               #
#############################################################################################
        wait
        sleep 1
}


##############################################################################
# Procedure: terminate_telnet_ssh_session
#
# Arguments:
#          argv1 : ssh / telnet
##############################################################################
proc terminate_telnet_ssh_session {INPUT} {

   if { $INPUT == "telnet"} {
        sleep 1
        puts "##########################################################################"
        puts "                     Terminate telnet Session"
        puts "##########################################################################"
        send “35\r”
        expect "telnet>" { send "q\r\r"
                            puts "telnet session terminated successfully"}
        expect eof
        wait
        sleep 1
   } elseif {$INPUT == "ssh"} {
        sleep 1
        puts "##########################################################################"
        puts "                     Terminate ssh Session"
        puts "##########################################################################"
        send "exit\r"
        expect "Goodbye." { puts "ssh session terminated successfully." }
        expect eof
        wait
        sleep 1
   }

   return
}


##############################################################################
# Procedure: reconnect_to_rg
#
# Arguments:
#           arg1: <username>
#           arg2: <ip address>
#           arg3: <password>
##############################################################################
proc reconnect_to_rg {USERNAME IP_ADDRESS PWD} {
        global  CLI_PROMPT
        global  PRE_CLI_PROMPT

        puts "#################################################################"
        puts "#             reconnect_to_rg                              "
        puts "#################################################################"
        spawn  telnet $IP_ADDRESS

        #################################################################
        # Enter Login and user name
        #################################################################
        expect  "*login:*" { send "$USERNAME\r"}
        expect  "*Password:*" {send "$PWD\r" }
        sleep 1

        puts "\n\n\n***********************************************************"
        puts "Debug: Entered username is $USERNAME"
        puts "Debug: Entered password is $PWD"
        puts "***********************************************************"

        #################################################################
        # Enter Into pre-cli prompt :
        #################################################################
        expect $PRE_CLI_PROMPT {send "cli\r"}

        puts "\n\n\n***********************************************************"
        puts "Status: entering into cli prompt"
        puts "\n***********************************************************"

        sleep 1
        return
}


##############################################################################
# Procedure: test_telnet_to_rg
#
# Arguments:
#           arg1: <test case no.>
#           arg2: <username>
#           arg3: <ip address>
#           arg4: <password>
##############################################################################
proc test_telnet_to_rg {TESTCASE_NUM  USERNAME IP_ADDRESS PWD} {
        global  PRE_CLI_PROMPT

        puts "\n\n\n$################################################"
        puts "Debug: Entered username is $USERNAME"
        puts "Debug: Entered password is $PWD"
        puts "$################################################"
        #################################################################
        #             spawn telnet to RG session
        #################################################################
        spawn  telnet $IP_ADDRESS

        #################################################################
        # Enter Login and user name
        #################################################################
        expect  "*login:*" { send "$USERNAME\r"}
        expect  "*Password:*" {send "$PWD\r" }
        sleep 1

        if {$USERNAME eq "user" & $PWD eq ""} {
            expect "Login incorrect"  {
                                        puts "\n\n#################################################################"
                                        puts "Test case $TESTCASE_NUM: $USERNAME account, default pwd:$PWD PASSED"
                                        puts "###################################################################"
                                        terminate_telnet_ssh_session telnet
                                        return
            }
            # If user account sdb password parameter is empty, then user login should fail
            # even when default password is empty.
            puts "\n\n#################################################################"
            puts "Test case $TESTCASE_NUM: $USERNAME account, default pwd:$PWD FAILED"
            puts "###################################################################"
            terminate_telnet_ssh_session telnet
            return
        }

        # If login is successful, test case is passed.
        expect "$USERNAME completed login" {
                                  puts "\n\n##################################################################"
                                  puts "Test case $TESTCASE_NUM: $USERNAME account, default pwd:$PWD PASSED"
                                  puts "####################################################################"
                                  terminate_telnet_ssh_session telnet
                                  return
                                 }

        # If login is not successful, test case is failed.
        puts "\n\n#####################################################"
        puts "Test case $TESTCASE_NUM: $USERNAME account, default pwd:$PWD FAILED"
        puts "#####################################################"

        terminate_telnet_ssh_session telnet

        return
}

##############################################################################
# Procedure: test_ssh_to_rg
#
# Arguments:
#           arg1: <test case no.>
#           arg2: <username>
#           arg3: <ip address>
#           arg4: <password>
##############################################################################
proc test_ssh_to_rg {TESTCASE_NUM  USERNAME IP_ADDRESS PWD} {
        puts "\n\n\n$################################################"
        puts "Debug: Entered username is $USERNAME"
        puts "Debug: Entered password is $PWD"
        puts "$################################################"

        #################################################################
        #             spawn ssh to RG session
        #################################################################
        spawn ssh $USERNAME@$IP_ADDRESS

        expect "*password" {send "$PWD\r"}
        # If ssh login is successful, test case is failed
        expect "$USERNAME completed login" {
                                  puts "\n\n################################################################"
                                  puts "Test case $TESTCASE_NUM: $USERNAME account, default pwd:$PWD PASSED"
                                  puts "##################################################################"
                                  terminate_telnet_ssh_session ssh
                                  return
                                           }
        # If ssh login fails, test case is failed
        puts "\n\n################################################################"
        puts "Test case $TESTCASE_NUM: $USERNAME account, default pwd:$PWD FAILED"
        puts "##################################################################"

        terminate_telnet_ssh_session ssh
        return
}


#################################################################################################################
#                          MAIN      SCRIPT      STARTS      HERE
#################################################################################################################

#################################################################
#             spawn telnet to RG session
#################################################################
spawn  telnet 192.168.1.254

#################################################################
# Enter Login and user name
#################################################################
expect  "*login:*" { send "$ADMIN_USER_NAME\r"}
expect  "*Password:*" {send "$ADMIN_PASSWORD\r" }
sleep 1

puts "\n\n\n***********************************************************"
puts "Debug: Entered username is $ADMIN_USER_NAME"
puts "Debug: Entered password is $ADMIN_PASSWORD"
puts "***********************************************************"


#################################################################
# Enter Into pre-cli prompt :
#################################################################
expect $PRE_CLI_PROMPT {send "cli\r"}

puts "\n\n\n***********************************************************"
puts "Status: entering into cli prompt"
puts "\n***********************************************************"

sleep 1

expect $CLI_PROMPT { send "\r\r"
                       sleep 1 }

puts "\n\n\n*********************************************************"
puts "Status: entered cli prompt successfully"
puts "*********************************************************"

#####################################################################################
#
#                           Enter Into nsh prompt                                   #
#
#####################################################################################
expect $CLI_PROMPT { send "!nsh\r" }

expect "*login*" { send "admin\r" }
expect "*Password:*" {send "$ADMIN_PASSWORD\r\r\r\r"}

sleep 1


##########################################################################################
#
#              why send "[xyz\r]" should be in send "\[xyz\r\]"
##########################################################################################
#       -re "[sudo] password for subhasish:" {send "$password\r"}
#       In Tcl (and hence in expect) the square brackets are the syntax
#       for command substitution (like backticks in the shell). So you
#       either need to escape the brackets or use different quotes that
#       prevent various expansions:
#
#       -re {[sudo] password for subhasish:} {send "$password\r"}
#       That brings up a different issue: are you expecting to see these
#       exact characters? Because you're instructing expect to treat that as
#       a regular expression, and square brackets in a regular expression means
#       a character class, so it will match a single character,
#       either a 's', 'u', 'd' or 'o'. So what you probably need is this:
#       -re {\[sudo\] password for subhasish:} {send "$password\r"}
###########################################################################################

puts "\n##########################################################################"
puts "         DISPLAY THE DEFAULT VALUES IN ALL MANAGEMENT ACCOUNTS"
puts "##########################################################################"

for {set acc_number 1} {$acc_number < 8 } {incr acc_number}  {
     expect $NEW_PROMPT {send  "get mgmt.account\[$acc_number\].password\r"}
     sleep 1
}

expect $NEW_PROMPT {send "exit\r"}

puts "\n##########################################################################"
puts "                          Testing Begins                                 "
puts "##########################################################################"


#############################################################################################
#                               ITERATION BEGINS                                            #
#############################################################################################

set count 0

foreach password $pwd_list {
        puts "\n##########################################################################"
        incr count
        set length [string length $password]
        puts "Iteration $count Password: $password Length: $length"
        puts "\n##########################################################################"

        puts "\n##########################################################################"
        puts "      In cli prompt, enter TR69 commands for setting admin, user "
        puts "      and remotessh passwords."
        puts "##########################################################################"

        expect $CLI_PROMPT {
                       puts "\n#####################################################################"
                       send "tr69 set tr69_residential_gateway_device.User.1.Password=$password\r"
                       expect "SetParameterValues successful" { puts "tr69 parameter user 'admin' set success"}
                       sleep 1
                       puts "\n#####################################################################"
                      }


        expect $CLI_PROMPT {
                       puts "\n#####################################################################"
                       send "tr69 set tr69_residential_gateway_device.User.2.Password=$password\r"
                       expect "SetParameterValues successful" { puts "tr69 parameter user 'user' set success"}
                       puts "#####################################################################"
                       sleep 1
                     }

        expect $CLI_PROMPT {
                       puts "\n#####################################################################"
                       send "tr69 set tr69_residential_gateway_device.User.7.Password=$password\r"
                       expect "SetParameterValues successful" { puts "tr69 parameter user 'remotessh' set success"}
                       puts "#####################################################################"
                       sleep 1

                      }

         ###################################################################################################
         # Exit from the session now
         ###################################################################################################
         terminate_session_from_RG_CLI_PROMPT


         ###################################################################################################
         # Testing telnet connection for accounts: 'admin', 'user' and ssh connection for account 'remotessh'
         ###################################################################################################

         puts "#####################################################################"
         puts "# Iteration:$count  Password:$password  Account:admin Length: $length"
         puts "#####################################################################"
         test_telnet_to_rg  1 admin "192.168.1.254" $password

         sleep 2

         puts "#####################################################################"
         puts "# Iteration:$count  Password:$password  Account:user Length: $length"
         puts "#####################################################################"
         test_telnet_to_rg  2  user "192.168.1.254"  $password

         sleep 2

         puts "#####################################################################"
         puts "# Iteration:$count  Password:$password  Account:remotessh Length: $length"
         puts "#####################################################################"
         test_ssh_to_rg  3 remotessh "192.168.1.254" $password

         sleep 2

         ###################################################################################################
         #       Reconnect to RG via telnet
         ###################################################################################################
         #################################################################
         #             spawn telnet to RG session
         #################################################################
         spawn  telnet 192.168.1.254
         expect  "*login:*" { send "$ADMIN_USER_NAME\r"}
         expect  "*Password:*" {send "$password\r" }
         sleep 1

         puts "\n\n\n***********************************************************"
         puts "Debug: Entered username is $ADMIN_USER_NAME"
         puts "Debug: Entered password is $password"
         puts "***********************************************************"

         #################################################################
         # Enter Into pre-cli prompt :
         #################################################################
         expect $PRE_CLI_PROMPT {send "cli\r"}

         puts "\n\n\n***********************************************************"
         puts "Status: entering into cli prompt"
         puts "\n***********************************************************"

         sleep 1
}


#############################################################################################
#                               ITERATION ENDS                                              #
#############################################################################################

pre-requisites for installing speech recognition and speech to text python libraries

sudo apt update && sudo apt upgrade

sudo apt-get install libportaudio2
sudo apt install libasound-dev portaudio19-dev libportaudio2 libportaudiocpp0 ffmpeg libav-tools

pip3 install --upgrade pip

pip3 install SpeechRecognition
sudo apt-get install python3-setuptools

pip3 install pyaudio  

pip3 install pocketsphinx  


http://www.codesofinterest.com/2017/03/python-speech-recognition-pocketsphinx.html
http://www.codesofinterest.com/2017/01/audio-classification-pyaudio-getting-started.html

python code to telnet to remote session using python telnetlib library

import getpass
import sys
import telnetlib
import time


print("Trying to authenticate to the telnet server")
tn = telnetlib.Telnet('192.168.1.254', timeout=10)

#tn.set_debuglevel(9)

# The first argument is a list of regular expressions,
# either compiled (regex objects) or uncompiled (strings).
# The optional second argument is a timeout, in seconds;
# the default is to block indefinitely.

tn.expect(["Login: ", "login: "], 5)
tn.write('admin' + "\r\n")
tn.expect(["Password: ", "password"], 5)
tn.write('admin123' + "\r\n")

print(" Username and Password Successful.. telnet connection established")
tn.interact()

Python code to edit excel sheet using openpyxl library

import openpyxl

# F:\Neelkanth Python Research
# The openpyxl.load_workbook() function takes in the flename and returns
# a value of the workbook data type. This Workbook object represents the Excel
# file, a bit like how a File object represents an opened text file.
wb = openpyxl.load_workbook('F:/Neelkanth_Python_Research/sockets vs mq latency.xlsx')
print(type(wb))

# print sheets from workbook
print(wb.get_sheet_names())

sheet1 = wb['MQ non-blocking']
print('######### sheet1.title ###########')
print(sheet1.title)
print('##################################')


for i in range(5, 15,1):
    print(i, sheet1.cell(column= 6,row = i).value,
          sheet1.cell(column= 7,row = i).value)
    a = sheet1.cell(column= 7,row = i).value -  sheet1.cell(column= 6,row = i).value
    a = round(a * 1000000, 0)
    sheet1.cell(column = 8, row = i).value = a

wb.save('F:/Neelkanth_Python_Research/new_1.xlsx')






python program to print the no. of occurances of a word in a sentence

python program to print the no. of occurences of a 'character' in a sentence

import pprint

#python program to print the no. of occurances of a word in a sentence

message = 'I am captain Neel jack sparrow. the quest for knowledge is a never ending process'

# first define a dictonary
count = {}

# loop for each character in message
for character in message:
    # if the character is not present in the dictionary, it will be stored
    # and the default value will be set to 0.
    # if the character is already present, the default value 0 will not be set.
    count.setdefault(character, 0)
    # in the dictionary, character is the key and value is the no. of it's occurance 
    # increment the value by 1 for each key i.e character
    count[character] = count[character] + 1

#pretty printing        

pprint.pprint(count)


Output:

{' ': 14,
 '.': 1,
 'I': 1,
 'N': 1,
 'a': 6,
 'c': 3,
 'd': 2,
 'e': 10,
 'f': 1,
 'g': 2,
 'h': 1,
 'i': 3,
 'j': 1,
 'k': 2,
 'l': 2,
 'm': 1,
 'n': 5,
 'o': 4,
 'p': 3,
 'q': 1,
 'r': 5,
 's': 5,
 't': 3,
 'u': 1,
 'v': 1,
 'w': 2}
{' ': 14,
 '.': 1,
 'I': 1,
 'N': 1,
 'a': 6,
 'c': 3,
 'd': 2,
 'e': 10,
 'f': 1,
 'g': 2,
 'h': 1,
 'i': 3,
 'j': 1,
 'k': 2,
 'l': 2,
 'm': 1,
 'n': 5,
 'o': 4,
 'p': 3,
 'q': 1,
 'r': 5,
 's': 5,
 't': 3,
 'u': 1,
 'v': 1,
 'w': 2}

Expect script for automating system v message queue and unix domain socket c program

Expect script for automating system v message queue and unix domain socket c program

C program for System V Message Queue vs Unix Domain socket, 50000 messages 'send' timestamp capture


#!/usr/bin/expect -f

# set expect timeout to 80 secs
set timeout 80
# Max no. of iterations for each case 10
set MAX_ITERATION 10

#################################################################################################################
#                                       PROCEDURES / FUNCTIONS
#################################################################################################################


#########################################################
#           Terminate the Session
#########################################################
proc terminate_session {} {
# Send special ^] to telnet so we can tell telnet to quit.
    expect "# " { send “35\r” }
    expect "telnet>" { send "q\r\r" }
    expect eof
#  You should also, either call "wait" (block) for process to exit or "wait -nowait"
#  (don't block waiting) for process exit.
#  Without "wait", expect may sever the connection to the process prematurely, this
#  can cause the creation zombies in some rare cases. If the application did not get our
#  signal earlier (the EOF from close), or if the process doesn't interpret EOF as an exit
#  status then it may also continue running and your script would be none the wiser.
#  With wait, we ensure we don't forget about the process until it cleans up and exits.
#  <  in short, wait is to clean up zombies >
        wait
        sleep 1
}

#########################################################
#           connect to RG and restart the Session
#########################################################
proc restart_session {} {
# spawn telnet to RG session
    spawn  telnet 192.168.1.254

# expect login and password. this is must
    expect "*login:*" { send "admin\r"}
    expect "*Password:*" {send "admin123\r"
    }

    expect "NOS/1234567888>" {send "magic\r"}
    expect "NOS/1234567888/DEBUG/MAGIC" {send "!\r"}

    expect "# " {
        send "pwd\r"
            send "cd /bin\r"
            send "killall udp_server\r"
            send "killall mq_server\r"
            send "./udp_server &\r"
            sleep 1
            send "./mq_server &\r"
            sleep 1
            send "\r\r\r"
    }
}

#########################################################
#    after every iteration terminate the connection
#    to RG and restart the session
#########################################################
proc terminate_and_restart {} {
     terminate_session
     restart_session
}


#################################################################################################################
#                          MAIN      SCRIPT      STARTS      HERE
#################################################################################################################
# spawn telnet to RG session
spawn  telnet 192.168.1.254

# expect login and password. this is must
expect "*login:*" { send "admin\r"}
expect "*Password:*" {send "admin123\r"
}

expect "NOS/1234567888>" {send "magic\r"}
expect "NOS/1234567888/DEBUG/MAGIC" {send "!\r"}

expect "# " {
    send "pwd\r"
        send "cd /bin\r"
        send "killall udp_server\r"
        send "killall mq_server\r"
        send "./udp_server &\r"
        sleep 1
        send "./mq_server &\r"
        sleep 1
        send "\r\r\r"
}

################################################################################################
#     Message queue  (client socket mode: Blocking)
################################################################################################

##################################
#         100 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 100 bytes Iteration $x\r"
            send "./mq_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf bl no\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
        sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

##################################
#         500 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 500 bytes Iteration $x\r"
            send "./mq_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf bl no\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
        sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

##################################
#         1000 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 1000 bytes Iteration $x\r"
            send "./mq_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf bl no\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
        sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

##################################
#         1500 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 1500 bytes Iteration $x\r"
            send "./mq_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf bl no\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
        sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

##################################
#         2000 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 2000 bytes Iteration $x\r"
            send "./mq_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf  bl no\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
        sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

################################################################################################
#     Unix domain sockets (client socket mode: Blocking)
################################################################################################

##################################
#         100 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 100 bytes Iteration $x\r"
            send "./udp_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf bl no\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
        sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

##################################
#         500 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 500 bytes Iteration $x\r"
            send "./udp_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf bl no\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
        sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

##################################
#         1000 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 1000 bytes Iteration $x\r"
            send "./udp_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf  bl no\r"
            expect "*Client: bye*" {send "\r\r"}
        send "pwd\r"
        sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

##################################
#         1500 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 1500 bytes Iteration $x\r"
            send "./udp_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf  bl no\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
        sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

##################################
#         2000 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 2000 bytes Iteration $x\r"
            send "./udp_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf  bl no\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
        sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

################################################################################################
#     Message queue  (client socket mode: Non-Blocking with no sleep between each send )
################################################################################################

##################################
#         100 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 100 bytes Iteration $x\r"
            send "./mq_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf nb no\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
            sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

##################################
#         500 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 500 bytes Iteration $x\r"
            send "./mq_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf nb no\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
            sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

##################################
#         1000 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 1000 bytes Iteration $x\r"
            send "./mq_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf nb no\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
            sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

##################################
#         1500 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 1500 bytes Iteration $x\r"
            send "./mq_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf nb no\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
            sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

##################################
#         2000 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 2000 bytes Iteration $x\r"
            send "./mq_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf  nb no\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
            sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

################################################################################################
#     Unix domain sockets (client socket mode: Non-Blocking with no sleep between each send)
################################################################################################

##################################
#         100 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 100 bytes Iteration $x\r"
            send "./udp_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf nb no\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
            sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

##################################
#         500 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 500 bytes Iteration $x\r"
            send "./udp_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf nb no\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
            sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

##################################
#         1000 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 1000 bytes Iteration $x\r"
            send "./udp_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf  nb no\r"
            expect "*Client: bye*" {send "\r\r"}
        send "pwd\r"
            sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

##################################
#         1500 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 1500 bytes Iteration $x\r"
            send "./udp_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf  nb no\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
            sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

##################################
#         2000 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 2000 bytes Iteration $x\r"
            send "./udp_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf  nb no\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
            sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

################################################################################################
#     Message queue  (client socket mode: Non-Blocking with sleep between each send )
################################################################################################

##################################
#         100 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 100 bytes Iteration $x\r"
            send "./mq_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf nb yes\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
            sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

##################################
#         500 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 500 bytes Iteration $x\r"
            send "./mq_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf nb yes\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
            sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

##################################
#         1000 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 1000 bytes Iteration $x\r"
            send "./mq_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf nb yes\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
            sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

##################################
#         1500 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 1500 bytes Iteration $x\r"
            send "./mq_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf nb yes\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
            sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

##################################
#         2000 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 2000 bytes Iteration $x\r"
            send "./mq_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf  nb yes\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
            sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

################################################################################################
#     Unix domain sockets (client socket mode: Non-Blocking with no sleep between each send)
################################################################################################

##################################
#         100 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 100 bytes Iteration $x\r"
            send "./udp_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf nb yes\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
            sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

##################################
#         500 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 500 bytes Iteration $x\r"
            send "./udp_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf nb yes\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
            sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

##################################
#         1000 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 1000 bytes Iteration $x\r"
            send "./udp_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf  nb yes\r"
            expect "*Client: bye*" {send "\r\r"}
        send "pwd\r"
            sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

##################################
#         1500 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 1500 bytes Iteration $x\r"
            send "./udp_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf  nb yes\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
            sleep 2
    }
    send "\r\r\r"
}

terminate_and_restart
sleep 2

##################################
#         2000 bytes
##################################
expect "# " {
    for {set x 1} {$x <= $MAX_ITERATION} {incr x} {
        send "echo 2000 bytes Iteration $x\r"
            send "./udp_client sjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldfsjkhsdfsdfsfsldakfhsldkfjhsadlfhsldafjkhsladfhsldf  nb yes\r"
            expect "*Client: bye*" { send "\r\r"}
        send "pwd\r"
            sleep 2
    }
    send "\r\r\r"
}

#####################  END OF SCRIPT ####################################

interact



Expect script to print the content of files 

#!/usr/bin/expect -f

# set expect timeout to 80 secs
set timeout 80
# Max no. of iterations for each case 10
set MAX_ITERATION 10

#################################################################################################################
#                                       PROCEDURES / FUNCTIONS
#################################################################################################################


#########################################################
#           Terminate the Session
#########################################################
proc terminate_session {} {
# Send special ^] to telnet so we can tell telnet to quit.
    expect "# " { send “35\r” }
    expect "telnet>" { send "q\r\r" }
    expect eof
#  You should also, either call "wait" (block) for process to exit or "wait -nowait"
#  (don't block waiting) for process exit.
#  Without "wait", expect may sever the connection to the process prematurely, this
#  can cause the creation zombies in some rare cases. If the application did not get our
#  signal earlier (the EOF from close), or if the process doesn't interpret EOF as an exit
#  status then it may also continue running and your script would be none the wiser.
#  With wait, we ensure we don't forget about the process until it cleans up and exits.
#  <  in short, wait is to clean up zombies >
        wait
        sleep 1
}

#########################################################
#           connect to RG and restart the Session
#########################################################
proc restart_session {} {
# spawn telnet to RG session
    spawn  telnet 192.168.1.254

# expect login and password. this is must
    expect "*login:*" { send "admin\r"}
    expect "*Password:*" {send "admin123\r"
    }

    expect "NOS/1234567888>" {send "magic\r"}
    expect "NOS/1234567888/DEBUG/MAGIC" {send "!\r"}

    expect "# " {
        send "pwd\r"
            send "cd /bin\r"
            send "killall udp_server\r"
            send "killall mq_server\r"
            send "./udp_server &\r"
            sleep 1
            send "./mq_server &\r"
            sleep 1
            send "\r\r\r"
    }
}

#########################################################
#    after every iteration terminate the connection
#    to RG and restart the session
#########################################################
proc terminate_and_restart {} {
     terminate_session
     restart_session
}


#################################################################################################################
#                          MAIN      SCRIPT      STARTS      HERE
#################################################################################################################
# spawn telnet to RG session
spawn  telnet 192.168.1.254

# expect login and password. this is must
expect "*login:*" { send "admin\r"}
expect "*Password:*" {send "admin123\r"
}

expect "NOS/1234567888>" {send "magic\r"}
expect "NOS/1234567888/DEBUG/MAGIC" {send "!\r"}

expect "# " {
    send "pwd\r"
        send "cd /data/system\r"
        send "\r\r"
        send "cat mq_client_bl_no_100\r"
        send "\r\r"
        send "cat mq_client_bl_no_500\r"
        send "\r\r"
        send "cat mq_client_bl_no_1000\r"
        send "\r\r"
        send "cat mq_client_bl_no_1500\r"
        send "\r\r"
        send "cat mq_client_bl_no_2000\r"
        send "\r\r"
        send "cat udp_client_bl_no_100\r"
        send "\r\r"
        send "cat udp_client_bl_no_500\r"
        send "\r\r"
        send "cat udp_client_bl_no_1000\r"
        send "\r\r"
        send "cat udp_client_bl_no_1500\r"
        send "\r\r"
        send "cat udp_client_bl_no_2000\r"
        send "\r\r"
        send "cat mq_client_nb_no_100\r"
        send "\r\r"
        send "cat mq_client_nb_no_500\r"
        send "\r\r"
        send "cat mq_client_nb_no_1000\r"
        send "\r\r"
        send "cat mq_client_nb_no_1500\r"
        send "\r\r"
        send "cat mq_client_nb_no_2000\r"
        send "\r\r"
        send "cat udp_client_nb_no_100\r"
        send "\r\r"
        send "cat udp_client_nb_no_500\r"
        send "\r\r"
        send "cat udp_client_nb_no_1000\r"
        send "\r\r"
        send "cat udp_client_nb_no_1500\r"
        send "\r\r"
        send "cat udp_client_nb_no_2000\r"
        send "\r\r"
        send "cat mq_client_nb_yes_100\r"
        send "\r\r"
        send "cat mq_client_nb_yes_500\r"
        send "\r\r"
        send "cat mq_client_nb_yes_1000\r"
        send "\r\r"
        send "cat mq_client_nb_yes_1500\r"
        send "\r\r"
        send "cat mq_client_nb_yes_2000\r"
        send "\r\r"
        send "cat udp_client_nb_yes_100\r"
        send "\r\r"
        send "cat udp_client_nb_yes_500\r"
        send "\r\r"
        send "cat udp_client_nb_yes_1000\r"
        send "\r\r"
        send "cat udp_client_nb_yes_1500\r"
        send "\r\r"
        send "cat udp_client_nb_yes_2000\r"
}
        send "\r\r"

interact


Plotting a graph using matplotlib python library