Expect Script Aborts Before Completion


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expect Script Aborts Before Completion
# 1  
Old 03-21-2012
Expect Script Aborts Before Completion

Hi guys, i have a script that logs into a range of hosts and runs an update involving apt-get: apt-get update

problem i'm having is, before i do the apt-get, i do a apt-get update. and this process is completed quickly for most servers. but some servers, it can take a while.

my expect script aborts and moves on to the next server if the update isn't done quickly.

i know that the option for "timeout" can be used. but that isn't working as expected. when i use timeout, the script logs into the server, then does nothing until the timeout specified has expired. then it runs the commands its suppose to run. this is not good. i want the script to log into the server, immediately run the command, then exits out of the system only if the command has completed.

Can someone please help me modify this?

below is my script:

Code:
#!/usr/bin/expect -f

if {[llength $argv] < 1 } {

puts "Incorrect arguments. Enter following syntax:\n"
puts " tn <node to telnet to> \n\r"
puts "Example: \n"
puts " tn ottud023 \n\r\n\r"
exit 1

}

set wsname [lindex $argv 0]
set usepas [lindex $argv 1]
set usersname [lindex $argv 2]
set remotecommand [lindex $argv 3]

set displayno 0
set prompt "(%|#|:|]|\\$|%]) $"


spawn ssh $wsname -l $usersname
set spwnid1 $spawn_id

expect {
-i $spwnid1
"(yes/no)?" {
send "yes \r"
}
"assword" {
send "$usepas \r"
}
}

set prompt "(%|#|\\$|%]) $"

expect -re $prompt
send -- "$remotecommand \r"
expect "assword"
send -- "$usepas\r"
expect -re $prompt
send -- "exit \r"

# 2  
Old 03-22-2012
where did you put the timeout?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with delaying script and implementing checks before completion

Hello everyone, I was wondering if any of you could help me with this. I am an absolute beginner and don't know how to program, but I can follow a tutorial and tweak code sometimes. My understanding of programing is limitted to what for and while loops do, and how if then else logic works. That... (2 Replies)
Discussion started by: tomeurp
2 Replies

2. Programming

Expect script returning string following a found expect.

I'm fairly new to scripting so this might not be possible. I am using Expect with Cisco switches and need to capture the string after finding the expect request. For example, when I issue "show version" on a Nexus switch, I'm looking to capture the current firmware version: #show version ... (0 Replies)
Discussion started by: IBGaryA
0 Replies

3. HP-UX

Fbackup aborts exactly at 2 GB

i tried to take a backup by using fbackup command. But it exactly aborted after taking backup of 2GB data. pleasse guide me how should i proceed to overcome this problem. The command i used is: fbackup -0 -y -f /dir1 \ -g fbackup_graph \ -c fbackup_config ... (6 Replies)
Discussion started by: siva3492
6 Replies

4. UNIX for Dummies Questions & Answers

Bash-completion on shell script

Hello I want use bash_completion on a script but the information on the internet give me not a solution. The scrip start with "cd" to a direction Than the script do "ls" Than I must give a name of a sub-direction and here I want to use <TAB>, so when I have a direction with the name smith... (2 Replies)
Discussion started by: thailand
2 Replies

5. Programming

Calling another expect script inside an expect script

I have an expect script called remote that I want to call from inside my expect script called sudoers.push, here is the code that is causing me issues: set REMOTE "/root/scripts/remote" ... log_user 1 send_user "Executing remote script as $user...\n" send_user "Command to execute is: $REMOTE... (1 Reply)
Discussion started by: brettski
1 Replies

6. Programming

Calling expect script inside another expect

Hi, Am very new to expect scripting.. Can You please suggest me how to call an expect script inside another expect script.. I tried with spawn /usr/bin/ksh send "expect main.exp\r" expect $root_prompt and spawn /usr/bin/ksh send "main.exp\r" expect $root_prompt Both... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

7. Shell Programming and Scripting

Need help with Expect script for Cisco IPS Sensors, Expect sleep and quoting

This Expect script provides expect with a list of IP addresses to Cisco IPS sensors and commands to configure Cisco IPS sensors. The user, password, IP addresses, prompt regex, etc. have been anonymized. In general this script will log into the sensors and send commands successfully but there are... (1 Reply)
Discussion started by: genewolfe
1 Replies

8. Slackware

pkgtool aborts

Hi everyone! I am running Slackware 12.1 and the past few days I have this problem: Whenever I use pkgtool to install an update, I get this message: /sbin/installpkg: line 231: 3967 Aborted /sbin/ldconfig I tried ldconfig but it aborts. Any ideas would help, Thanks... (2 Replies)
Discussion started by: kerb41
2 Replies

9. UNIX for Dummies Questions & Answers

Script to check process completion

Hi, OS - Unix Iam doing the following: after login to the unix box 1. change directory 2. run a shell script "preinstall.sh" 3. This takes apprx 5 mins 4. after which i use to change permission of a file "installhub.sh" (this file is generated from the previous step). Is there anyway... (2 Replies)
Discussion started by: kenkanya
2 Replies

10. 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
Login or Register to Ask a Question