I have a TCL expect script that spawns a telnet session to a Nortel DMS100 to execute some commands. The strange thing is that the response in expect_out is not consistent. It sometimes contains a extra enter or newline. This results in differences in the expect out buffer. Here is a part of the script:
send "time " sleep 1 expect -re ">"
[code]...
This command displays the time. The correct output should be (with log_user=1):
>time Time is 11:44:04 >
But sometimes the output is:
>timeTime is 11:45:04 >
As you can see here the is missing on the command that expect sends , or at least in the echo that is comming back. I use a split command to filter out the response in the expect_out buffer, but this fails when the is missing. Here is a example with the debug enabled:
[code]....
I suspect it has something to do with a slow response of the switch. I tried to send the time command slow and with the send_human but the result is the same. A timeout between the send and expect also doesn't help.
I want to write a function in expect/tcl which logins into a router. but the syntax is a little confusing .
case 1: router prompts for "username".. {we put in username and password .. if they are incorrect we try with another username and password. if we succeed into getting a prompt we return 1 .. if both username passwords are wrong or we time out we return 0 }
case 2: router prompts for "login" .. {we put in username and password .. if they are incorrect we try with another username and password. if we succeed into getting a prompt we return 1 .. if both username passwords are wrong or we time out we return 0 }
case 3: router prompts for "password" only .. { we login just using the password and get to the enable prompt}
I am trying to make a script that can be used to check server load on a remote server and produces sound on our local machine, when server load exceeds a particular limit.1. I want to execute command uptime or uptime | awk '{print$10}'on the remote server and store the result in a variable(say x), and later use it in the bash script.
I am moving my migration forward and am trying to get my expect scripts tested and found one that no longer works. Quite simply, it spawns a telnet session to a router.
#!/usr/bin/expect set env(TERM) vt100 set timeout 3 set send_human {.1 .3 1 .05 2} set timeout -1 # spawn telnet 10.254.3.232
and that's it. The result of the script is that the command to spawn simply shows up on the screen like it is a puts command. On my older openSUSE system, it worked fine. I am running Ubuntu v9.10 desktop, and expect and its libs are patched to the latest rev, expect is 5.43.0.
send "pen" (till the end of lines generated as in |more.... usually we use like 8 space bar buttons after "pen" to generate all) and I want to redirect the whole generated result of "pen" to results.
I have my router configured so that it drops outgoing telnet connections (and other protocols I don't use). It's a 2wire gateway. 192.168.1.65 is the internal IP of my ubuntu box.I'm trying to figure out what normal network traffic looks like and whether I should be worried by this log entry. At the time this happened I was testing out TOR (just navigating to a few sites (dell, ubuntu forums, etc.) nothing all that interesting.)
I'm trying to Use Expect to automate a curl function. basically I don't want to type enter for my script to run. Can anyone point me to a good Expect tutorial?
I am writing an expect script. At a certain point there is a rule that produces this debugging output:
Code:
expect: does " Address or name of remote host [x.x.x.x]? " (spawn_id exp8) match glob pattern " Address or name of remote host [x.x.x.x]? "? no This just times out When I use -exact for the expect keyword it does work What am I doing wrong? THe first should also match in my opinion because it is equal as well. Even if I remove the I still have the same issue if I try without -exact. I don't understand. I tried removing the but still got the same.
I'm using expect to log into a remote server and run a script. I want to able to have expect edit the output from that script, on the remote server, in VI. Has anyone ever done this before, it seems as though the expect interpreter has nothing to expect once VI is started, the file pointer starts at the beginning of the line, and expect usually reads the characters before the pointer.
I wrote an expect script that tests user authentication against a RADIUS server. The username is an email address, including an @ sign. I recently wrote an HTML/PHP front end to allow others to input username/password into a form and then see the results when they hit submit. Expect code that takes two args username, and password
Every works as it's supposed to, except for the output of the script. When it displays on the webpage, it's segmented weirdly with all throughout. What I've found is when I remove the @ sign in the username input, it fixes it. Is there any part of HTML or PHP that treats the @ as a special character? 1 more thing is that I have another HTML/PHP/EXP script that works fine with the @.
I am starting a new job, and need to brush up on my expect scripting. does anyone know of any online resources, e.g. telnet sites that I can play about with?
Is there a similar thing in expect, as there is 'read'(Read a line from standard input) in bash?I mean one could easily construct following script in bash:
I am having some difficulties with an expect script. What I want is that as soon as expect sees a newline followed by a dollarsign ($), that interact is done. So I would expect something like this to work:
Code: " $" { interact } However it doesn't. This is debugging output: Code: expect: continuing expect expect: does " " (spawn_id exp6) match glob pattern "#"? no
just as an excercise I'm trying to write a script that would automaticly install java using an expect script.I create the expect script with autoexpect and it works. But only if I don't change the size of the window. It always hang at the line with "--More--". So I changed the script and it boiled down to this
Code: set force_conservative 0 ;# set to 1 to force conservative mode even if ;# script wasn't run conservatively originally
I'll post the entire code here, and then specifically highlight what is just failing in a fashion I'm apparently incapable of fixing a few hours later:
Code:
#!/usr/bin/expect # The script should be called with a file in the directory called sshServerList # That file has the following format: # Line # | Contents of line
[code]....
I've had all kinds of different results and problems, but I've never been able to successfully log into multiple servers, though the first server in the list most times works okay (though might not on this iteration). I'm a bit hack and slash and I would be very greatful not only for a solution, but any tips on how I should have done this and places where I could clean up my code.
I've written an Expect script that assists with change management on Cisco devices. The script creates log files for pre-change, the change itself, and post-change. Each log and its commands is triggered by a ! command. For example:
Code:
./dochange.exp hostname <script spawns bash, user SSHes to hostname> !PRE
[code]....
All of this works fine. My big hair-pulling hiccup is that the resulting log files are filled with raw backspace characters! I am using log_file to log the output from the script. I stop and restart logging with a new file when needed. However, the log files are pretty much unusable. After doing some research, it looks like log_file sends output to the file in real-time, unbuffered. When I hit a key, it's immediately sent to the log. What I would like is for only the resulting string to go to the log. If I start to type 'reload' and instead type 'show run', I don't want 'reload' to be listed in the log at all.
I'm trying to create a program that would locate the oldest file of a certain type on a server. Here's the commands:
OLDEST_PATH=`find -L / -depth -maxdepth 6 -mindepth 6 -type d | sort -f | head -1` OLDEST_FILE=`find -L $OLDEST_PATH | grep .mp3 | sort -f | head -1` ls -al $OLDEST_FILE
I'm writing this all in expect but I'm having problems. The main problem I have is whenever I try to run the first command, I can't seem to isolate the result of the OLDEST_PATH so that the 2nd command will work. There always seems to be a newline in the variable and the result is only "find -L" command running and it bypasses the variable. If I can just figure out how to get the 1st and 2nd command to work, then I can figure out the 3rd. Here's some code:
I know there is a better way to write this. I've tried multiple ways and this just happens to be the last way I've tried it. If you try running this, you'll notice that there is still carriage returns after the result of OLDEST_PATH and it prevents the 2nd "find" command from working properly.
my tcl framework give exception - send: spawn id exp1025 not open - while executing command - exp_send "echo $ABC". Though this is very sporadic in nature and frequency of occurrence is very less, but still i need to fix it.
I have following queries
- why does this occur so sporadically?
- how do i fix it?
- what shall i do to avoid such exceptions in future.
Note : The function which runs the exp_send command always spawn a bash whenever it is called.
I have something like the following in my expect script:
Code:
interact { -nobuffer -re {^s } {
[code]....
I have put the "^" anchor to match only those pattern that does not have anything before "s" e.g.
1.when I type "s" followed by "enter" key it should match.
2.if I type something like "chess" followed by "enter" key it shouldn't match. the second case is also being matched by the regular expression I have in my code.
Is it possible to have an Expect script spawn an SSH session, log in, then go into interactive mode and give control of the SSH session to a Bash script? Here's a simplified example of the script so far: