Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calling anonther file from within an expect script....

Status
Not open for further replies.

GoneHiking

Technical User
Oct 27, 2006
19
US
Hello, I have a script that logs into a cisco switch, sends the info to a logfile, then logs out. What I then need to happen is to have the script "call" a separate file that is nothing more than a series of grep commands (all contained in a file that is set as an executable). My problem is that once the expect script ends and I tell it to log out of the switch, it won't run the second file.

I can run the two independently (i.e. I run the expect script to pull the data and store it in a file, then manually run the second file) and it works fine. I just can figure out a way to run the expect script AND run the other file using just the expect script.


Here's the expect script:

#!/usr/local/bin/expect --
log_file -noappend 1924log
spawn telnet $argv
expect -nocase "password:"
send "password\r"
send "s"
send "x"
send "n"
send "i"
send "x"
send "x"
send "f"
send "x"
send "x"
send "y\r"
send [exec mdso]
interact

===============

Here is the contents of the file named "mdso"

clear
cat 1924log | grep -i "Model Number:" | cut -c 24-40
cat 1924log | grep -i "name of system" | cut -c 54-80
cat 1924log | grep -i "\[I\] IP address" | cut -c 50-70
cat 1924log | grep -i "\[S\] Subnet mask" | cut -c 50-70
cat 1924log | grep -i "\[G\] Default gateway" | cut -c 50-70
cat 1924log | grep -i ": Standard Edition" | cut -c 6-13

======

Any ideas on how to make the expect script also run the second file (named "mdso")? Is there a way to "jump to the shell" while running an expect script so that I can execute another command, then return to the expect script?

Thanks,

Andy

 
Just exec "mdso" instead of sending it should work?

Expect is an extension of the TCL language, so any commands in TCL should work in expect scripts.

Annihilannic.
 
Well, I tried that and it still won't execute the file "mdso." The initial expect script completes with no problem, but it sill won't execute "mdso" before it completes running. Any other ideas?

Thanks for the reply,

Andy

 
I found that when I was testing using this complicated script:

Code:
#!/usr/bin/expect -f

exec "date";

That I got no output, however when I did this:

Code:
#!/usr/bin/expect -f

exec "date" > "/tmp/date.out";

The expected output was in that file. So it's possible that your script is executing, but expect is trapping the standard output somehow? I'm presuming that mdso is on the local host, i.e. where you're running the Expect script from?


Annihilannic.
 
Hello Annihilannic, I tried your latest suggestion and it didn't work. I'm not sure why the suggestions you give (and things I've tried) aren't working. The mdso file is in the same directory as the expect script. Running it my itself produces the desired output (it's permissions are set 700). I'm still trying things out and poking around Google for answers.

Thanks,

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top