I have been working on a expect script on AIX OS. The script should pick the server list from input file from while loop and proceed with an if condition to match a specific pattern then proceed. else proceed with else if and proceed with next steps.

Unfortunately the script doesn't provide any output. Doesn't report any error or print nothing


set timeout 15
#exp_internal 1
set ip_file "host.txt"
set fid [open $ip_file r]
while {[gets $fid ip] != -1} {
      if  {[regexp  \[AU*N\]\[Z\]\[1\]\[7\]\+ $ip]} {
           puts "Server Belongs to APC"  
           spawn ssh -J lauk576 padmin@$ip;
           expect "Password:";
           send "Helloworld123\n";
           expect "$";
           send "oem_setup_env\n";
           expect "#";
           send {lsmcode -A | sed -e "s/^/$(uname -n): /"};
           send "\n";
           expect "#";
           send "exit\n";
           expect "$";
           send "exit\n" ;
           expect eof
      } elseif {[regexp  \[EMEA*LC\]\[T\]\+ $ip]} {
                puts "Server Belongs to EMEA "  
                           expect eof

close $fid
  • 1
    Please show a sample of the host file so we can verify your regular expressions. – glenn jackman Jun 11 at 17:59
  • You should also show (a few sample lines of) your input file host.txt. – Bodo Jun 11 at 18:00
  • 1
    The only obvious thing I see is the expect eof in the elseif block: you haven't spawned anything there. – glenn jackman Jun 11 at 18:00
  • Host.txt file. AU345NZ17 EMEA753LCT AU7654NZ18 – satsensort Jun 11 at 18:03
  • 2
    You are not using the right regexp pattern. To match AU345NZ17 for example you would need something like regexp {AU.*NZ17} $ip (I've used {} instead of needing to use backslash so often). The actual pattern depends on what variety of names you want to match. – meuh Jun 11 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.