Expect Scripting Loop Argument Desperately Needed!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expect Scripting Loop Argument Desperately Needed!
# 1  
Old 06-18-2012
Expect Scripting Loop Argument Desperately Needed!

I am trying to create an Expect script that does the following:

1) Telnets to an IP address and logs in with user ID and Password

2) Issue a CLI command to the server that will output data of which I am particularly interested in a DS1 clock 'Slips' value. I want to be able to keep issuing the CLI command..........wait say 5 minutes...then issue the command again...wait 5 minutes....issue it again........and if the clock 'Slips' value is increasing, I want to input another CLI command to change the clock source which prevents the equipment from losing clocking and having to be reboot the server to restore call processing.
3) this script will be run randomly using crontab.

I am obviously using Expect/TCL off a Linux box. My current script is able to Telnet to the server and login successfully, issue the CLI commands and change the clock source accordingly. The crontab also works.
The issue is parsing this SLIPS value and putting this value in a loop to see if it is in fact incrementing over the 3 or 4 CLI command queries and if so, I need to initialize the clock source. I have no clue as to how to make this loop command syntax using Expect scripting.

So again, once the CLI is isssued the first time, there will be a SLIPS value within the output, that needs to be saved, .....5 minutes later....the same command is issued again to see if the SLIPS has increased.......5 minutes later....same command issued again....and if SLIPS has increased 3 times in a row after every inputted CLI command...then I need to issue the CLI command to switch the DS1 clock source.
Again, this script will be ran again using crontab.....likely every hour.

Here is my script contents to date:

#!/usr/bin/expect
spawn telnet 127.16.10.99/r
expect "Connected to 127.16.10.99.\r"
expect "Login:"
send "tester\r"
expect "password:\r"
send "esso123"
expect "Spirent#"
send "st t1 stat sl6di2"
# the above command outputs the following info on terminal

DS1 Stats:


Slot SL2/DI8(PRI)
StatusLayer1 Active
StatusLayer2 Active
FramingErrors 6
PathCodeViolations 0
LineCodeViolations 22439
Slips 2
DchTxFrames 18260
DchTxOctets 72765
DchTxFrameUnderrun 0
DchRxFrames 17816
DchRxOctets 72765
DchRxLenViolations 0
DchRxAbortedFrames 0

#what I need to do is take note of the 'Slips' value - currently is shows value of 2

# so I need to create a loop statement that stores this value and then sleeps for 5 minutes.......then issues the CLI command to the system again and checks Slips value and check if it has increased - if it does - sleep 5 minutes and then issue the CLI command again......if it has increased again.....then I will need to switch the clock source. Note - if the Slips value is not increasing after the CLI command, then i need to say within Loop statement to exit this procedure.

Any help would be greatly appreciated.....searching Google for specific examples pertaining to this scenario has been fruitless. I have the Expect manual by OReilly....and it hasn't been useful to me regarding this looping function needed.

Thank you for taking the time.

Last edited by dwightlaidler; 06-21-2012 at 10:58 AM.. Reason: more data and scripting example included
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expect help needed .. can i do this ?

hi all, i need to run expect and get the output into variables so my bash script can make decisions this is what i get currently Please wait while gathering statistics... 1: 0x60bf83c8 2: 0x60bf8d58 3: 0x60bf8d80 * 4: 0x60bf93a0 * 5: 0x62b0b4e0 6: 0x605938a0 7:... (13 Replies)
Discussion started by: ExpectHelpNeede
13 Replies

2. UNIX for Dummies Questions & Answers

UNIX advice needed desperately :/

Firstly I do need to state that I am turning here as a last resort. Im in my first year of a Computer Networking and technical support course, and as a first year I must complete a Introductory Unix/Linux class. I have been doing well in the course so far however I have been stumped on the final... (1 Reply)
Discussion started by: setaylor5
1 Replies

3. UNIX for Dummies Questions & Answers

help with shell scripting argument

#!/bin/bash echo "enter a file or directory name" read name if then echo " argument is file " ls -l $name | awk '{print $1,}' elif echo " argument is a directory" ls -l $name | awk '{print $1}' fi what i am trying to do. get input... (3 Replies)
Discussion started by: iluvsushi
3 Replies

4. Shell Programming and Scripting

Expect - Comparison of expect value and loop selection

Hello All, I am trying to automate an installation process using expect and sh script. My problem is that during the installation process the expected value can change according to the situation. For Example if this is a first time installation then at step 3 I'll get "Do you want to accept... (0 Replies)
Discussion started by: alokrm
0 Replies

5. Shell Programming and Scripting

Help needed with expect...(If telnet fails)

Hello I'm working using expect to automate telnet commands...i want to check if telnet fails and in this case...certain message should appear or certain word should be out in a file). Thses are the messages that apeear if telnet fails: Trying 172.16.3.115... telnet: Unable to connect... (0 Replies)
Discussion started by: Hossam_Nox
0 Replies

6. Shell Programming and Scripting

help needed with script that gets a filename as argument (with an if/else statement)

Hi, I am trying to create a script just to study BASH scripting, but I have some problems. I need to create a script that gets a filename as an argument. The script should behave as follows: • If the given file name already exists, inform the user and quit. • If the given file name does... (2 Replies)
Discussion started by: I-1
2 Replies

7. Shell Programming and Scripting

Help needed desperately

Hello Folks, i have written a script to nullify the log files in my dev environment but the log files are not getting nullified.Please find below my script and also thank you all in advance for your help. find /app -size +100000 -xdev -exec du -k {} \; 2>/dev/null | sort -nr |ls -1dF ... (2 Replies)
Discussion started by: Rayzone
2 Replies

8. Shell Programming and Scripting

Help needed in expect scripting.

Hi, I am new to expect scripting and need your help in the following task. I want an expect script to take the commands from an input file and then execute the commands and give the command execution output in an otput file. The command execution part is normal and I did it via script by... (2 Replies)
Discussion started by: Sooryaa
2 Replies

9. Shell Programming and Scripting

strange expect script behavior, or am i misunderstanding expect scripting?

Hello to all...this is my first post (so please go easy). :) I feel pretty solid at expect scripting, but I'm running into an issue that I'm not able to wrap my head around. I wrote a script that is a little advanced for logging into a remote Linux machine and changing text in a file using sed.... (2 Replies)
Discussion started by: v1k0d3n
2 Replies

10. Shell Programming and Scripting

Help needed desperately......

Hi guys, I want to execute an SQL script based on a condition.... I am writing a sample requirement... num = {some value} if(num == 0) then cat>> test.sql <<FIN select * from table_a FIN else cat>> test.sql << FIN select * from table_b FIN fi This is what i... (3 Replies)
Discussion started by: Payal Sharma
3 Replies
Login or Register to Ask a Question