I want to write a login script in expect. But I want this to be reused in different other scripts. I want to make all the login commands part of a bash subroutine. ie instead of
expect_login.sh
#!/bin/usr/expect -f
spawn ....
set ....
I want this:
expect_login
{
# put some necessary command to initiate expect program
spawn ...
set ...
}
so I would like to place this subroutine in one file/library that would be reused by many different scripts.
How can I do that?
Thanks
PS: Pardon my imprecise syntax of bash/expect. I just wanted to write in a pseudocode manner.
Best Answer
I would go for 2 part solution. One part is the expect script, the other part is the Shell script.
For the expect script, it should be a generic script that accept input, and produce output.
This is my example expect script that accept hostname and password, and will produce the vcprofile name for the server
In the shell script, I will call the expect script and providing it with the variable, in this case the hostname for vcsystem. The password is actually a pattern according to the hostname OA@XXXX - where the XXXX is the last 4 digit number of the server
With this 2 part solution, I can do something like this:
And it will print out the vcprofile for each of the servers in the file serverlist.txt