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
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
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
2. Shell Programming and 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
3. Shell Programming and 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
4. Shell Programming and Scripting
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
5. Shell Programming and Scripting
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
6. Shell Programming and Scripting
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
7. Shell Programming and Scripting
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
8. UNIX for Dummies Questions & Answers
#!/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
9. UNIX for Dummies Questions & Answers
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
10. Shell Programming and Scripting
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
LEARN ABOUT DEBIAN
net::cli::interact::transport::telnet
Net::CLI::Interact::Transport::Telnet(3pm) User Contributed Perl Documentation Net::CLI::Interact::Transport::Telnet(3pm)
NAME
Net::CLI::Interact::Transport::Telnet - TELNET based CLI connection
VERSION
version 1.121640
DECRIPTION
This module provides a wrapped instance of a TELNET client for use by Net::CLI::Interact.
INTERFACE
app
On Windows platforms you must download the "plink.exe" program, and pass its location to the library in this parameter. On other platforms,
this defaults to "telnet".
runtime_options
Based on the "connect_options" hash provided to Net::CLI::Interact on construction, selects and formats parameters to provide to "app" on
the command line. Supported attributes:
host (required)
Host name or IP address of the host to which the TELNET application is to connect.
reap
Only used on Unix platforms, this installs a signal handler which attempts to reap the "ssh" child process. Pass a true value to enable
this feature only if you notice zombie processes are being left behind after use.
COMPOSITION
See the following for further interface details:
o Net::CLI::Interact::Transport
AUTHOR
Oliver Gorwits <oliver@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Oliver Gorwits.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
perl v5.14.2 2012-06-12 Net::CLI::Interact::Transport::Telnet(3pm)