Programming :: Expect/TCL - Unable To Get The Correct Results
Feb 8, 2011
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.
View 1 Replies
ADVERTISEMENT
Dec 11, 2010
trying to see IF i dont get the right results repeat the command until it will or quit after 3 tries....
expect -exact "->"
send -- "test_read_register 0,0x37
"
if {! [regexp {Address 0x00000000} do send -- "test_read_register 0,0x37
[code]....
It should read
Read: Address 0x00000037, Data: 0x0000000b
but sometimes it comes out to this
Read: Address 0x00000000, Data: 0x00000000
therefore ill have to run the command again IF I Dont get the right results...
View 1 Replies
View Related
Jul 27, 2010
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.
Bash Part
#!/bin/bash
x=$(/root/Desktop/exp)
[code]...
View 1 Replies
View Related
Dec 8, 2010
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.
View 4 Replies
View Related
Nov 19, 2008
I'am new to expect how do i send function key F12 in an expect script?
View 1 Replies
View Related
Feb 2, 2011
I cannot sudo nor log into a second ssh session on my Ubuntu 10.10 server edition headless setup. Entering an incorrect password works as expected but the correct password gives errors, and on the second attempt a segfault. I recently changed my password as the old one was about to expire, that was 3 days ago, I can't find evidence that I have sudo'ed or logged in a second session since, I have been logged into it via ssh throughout all of it and I am still currently logged in. What should I do to correct this problem? I'm worried that by turning it off I will lose all access. Is the only option using a live cd to change the password?
[Code]...
View 1 Replies
View Related
Nov 2, 2010
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?
View 1 Replies
View Related
Jun 16, 2010
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.
View 5 Replies
View Related
Aug 9, 2010
I'm trying to use expect to telnet to web server and send HTTP command like POST, GET, etc.
Here's my code...
But this gives an error
couldn't read file "/cgi-bin/authgw-cgi": no such file or directory
I think this is because of /
How to send / in expect?
View 3 Replies
View Related
Mar 7, 2011
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.
spawn ssh user1@$remote_server
expect "password: "
send "$password
[code]....
View 2 Replies
View Related
May 21, 2011
I'm trying to use expect to get data from telnet
Here's my code :
Code:
set equipment [lindex $argv 0]
set trunk [lindex $argv 1]
set fraction [lindex $argv 2]
[Code]....
so in bold letter not send in 1 line, but i want sent it to 1 line
View 2 Replies
View Related
Apr 13, 2011
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
Code:
expect "#"
send "test aaa group radius [lindex $argv 0] [lindex $argv 1] new-code
"expect "#"
[code]....
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 @.
View 2 Replies
View Related
Jul 12, 2010
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?
View 4 Replies
View Related
Aug 2, 2010
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:
Code: > cat script.sh
#!/bin/bash
read -p "Username: " uname
[code]....
View 1 Replies
View Related
Oct 17, 2010
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
[Code]...
View 3 Replies
View Related
Mar 25, 2010
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
[code]....
View 3 Replies
View Related
Jul 29, 2010
I have a Thomson TG784 router, where I would like to log in automatically and execute dhcp server lease flush command.
When I log in using telnet, the process is following:
Code:
View 6 Replies
View Related
Nov 19, 2010
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}
View 3 Replies
View Related
Oct 4, 2010
I have the following code which I've thieved from here, there and everywhere:
Code:
[root@localhost /]# cat autossh
#!/usr/bin/expect -f
[code]....
View 3 Replies
View Related
Feb 8, 2011
I am writing an expect script and I wish to use environment variables that are defined outside of the script.
View 2 Replies
View Related
Dec 13, 2010
I am working on an expect script to login into a server and copy few wars across the folders. But when i execute it I am getting the following error:
[exec] loginServer.sh: spawn: not found.
[exec] loginServer.sh: expect: 0403-006 Execute permission denied.
[exec] send: -- unknown
The first line is : #!/usr/bin/expect -f.Is this anything to do with server setting or configuration that doesn't allow spawn??
View 3 Replies
View Related
Apr 14, 2011
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.
View 1 Replies
View Related
May 4, 2010
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:
Code:
send "find -L / -depth -maxdepth 6 -mindepth 6 -type d | sort -f | head -1
"
sleep 20
expect -re "(.*)
[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.
View 2 Replies
View Related
Apr 21, 2010
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.
View 3 Replies
View Related
Jan 22, 2010
I need to open a telnet session using a shell script that follows this format:
telnet 10.100.0.1
expect "Password:"
send <password>
[code]....
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.
View 3 Replies
View Related
Jul 3, 2009
I have this expect process:
Code:
spawn -noecho telnet my.host.com
expect {
[code]...
View 3 Replies
View Related
Nov 19, 2009
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:
Code:
#!/bin/bash
expect -c "
[code]....
View 4 Replies
View Related
Dec 2, 2010
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.
View 1 Replies
View Related
Mar 7, 2011
consider these lines of code and their outputs:
[CODE]
int C = 0;
fprintf(stdout, "
(C, ++C) Bef = %d, Aft = %d
", C, ++C);
fprintf(stdout, "(C++, C) Bef = %d, Aft = %d
", C++, C);
[Code].....
The only one that looks right to me is the second one. I get similar results using both gcc and g++.
View 4 Replies
View Related
May 10, 2010
Im having problems with this little thing in a C example Im doing. I want to show in the shell like this example:
Name Birthday
Tomas 13
Adrian 24
Nate 15
Im trying to use the printf function but the names doesnt have the same lenght. So I cant do it like this:
printf("Name Bithday
");
printf("%s %d
");
View 4 Replies
View Related