Expect looking for a loop of some kind.



About a year ago I was frustrated with have to manually check some
vpns every hour on the hour for cpu utilization. I did a little
research and found that expect was just the tool for going out and
interacting with command line interfaces, I bought the book and
created a small simple script that went out grabbed the data and
then it was parsed to a nice csv that could be looked at as needed
and eventually trended.

I have not done very much scripting since, but it seems now that
must make a very similar script except now I must make it available
for other people to use, I am trying to make an if statement or
while statement or a loop of some kind so that it will continue
until the all the choices are false.

Thank you in advance and sorry for the newbie question I?m sure once
I see an example it will seem obvious but right now I just can?t
figure it out.

Mike


#!/usr/bin/expect -f


#spawn ssh and put down what will come back

spawn ssh user@somevpn

# Here is where I would like a loop
# I have tried This :
#expect ?yes? { send ?yes\n? } \
# ?assword: ?{ send ?password?
#because there will be many new sites I need the rsa yes
#this works well as an OR statement I would like to
#know how have it the if statement till none of the above are true
#then go on to the next line or process
expect "user@somevpn's password:"

send "password\r"
# I am starting and stopping the logs to different files for
different reports
log_file -a /SCRIPTS/vpn/temp/sa_active.log
expect ">"
send "get sa active\r"
#this is another place where I would like to place a loop where it
#would repeat until it was false
#as this is a variable number of ?pages?
expect "\\--- more ---"
send "q"
log_file
sleep 1
expect ">"
log_file -a /SCRIPTS/vpn/temp/logevent.log
send "get log event | inc ocsp\r"
send "\r"
log_file
log_file -a /SCRIPTS/vpn/temp/e3.log
send "get int e3/1 screen\r"
expect "\\--- more ---"
send "\r"
expect "\\--- more ---"
send "\r"
log_file
expect ">"
log_file -a /SCRIPTS/vpn/temp/xauth.log
send "get xauth act\r"
expect "\\--- more ---"
send "\r"
expect "\\--- more ---"
log_file
send "\r"
send "q"
sleep 1
expect ">"
send "exit/r"


.



Relevant Pages

  • RE: Change of set display name
    ... Just missed it in the script... ... > for each objUser in objOU 'Loop through all OBJECTS in referenced OU ... > When you are unable to keep your eyes open, do go and sleep for few hours!!! ... >> I need something that will go to a specific OU and set the Display Name ...
    (microsoft.public.windows.server.scripting)
  • Re: Record active sessions via WMI but with a twist
    ... stop the do loop as soon as the specified time is reached? ... The problem is i want this to monitor active sessions reporting every ... onto the next section of the script. ... if it is calculate the time to sleep until 12:30" do you mean get the ...
    (microsoft.public.scripting.vbscript)
  • Re: MONITOR/WATCH DIRECTORY AND PROCESS??
    ... >What would be an efficient and proper way to implement a script ... >CPU power! ... Put a sleep in your loop, and don't do anything but check the directory ...
    (comp.unix.shell)
  • Re: Nonblocking Pipe Open
    ... Just after I posted my sample Perl script, ... write the same loop without sleep calls if I just use an inifnite loop ... might be difficult figuring out when a command has finished, ... sleep() calls). ...
    (comp.lang.perl.misc)
  • cant get out of infinite while loop
    ... To get into the infinite loop, I write to a file the "on" status ... writing switch on ... ready to sleep for 10 seconds ... or die "Problem passing files to the bridge directory...$!"; ...
    (comp.lang.perl.misc)