Expect script idles for a long time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expect script idles for a long time
# 1  
Old 03-25-2016
Expect script idles for a long time

the following code works sometimes. other times, it behaves mysteriously. when the script sshs to a box, it is suppose to automatically begin running the command it is told to run. but in this case, after this script logs into a host, it just sits there at the prompt and does not run the command.

i've changed the timeout to "set timeout -1" but that didn't help. any ideas?

Code:
                                        export nserver=$(echo ${line})
                                        export username="${USERSNAME}"
                                        export usepas="$NUPSSWD"
                                        export remotecom="${script}"
                                        export specialcomm=">> /tmp/loggs.txt"
                                        #spawn ssh $env(nserver) -l $env(username)

                                        /usr/bin/expect -c '

                                        set timeout 65

                                        spawn ssh $env(username)@$env(nserver)

                                        expect {
                                        "*password*" {
                                                send "$env(usepas)\r"
                                        }
                                        "*yes/no*" {
                                                send "yes\r" ; exp_continue
                                        }
                                        "*password:*" {
                                                send "$env(usepas)\r"
                                        } }

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

                                        expect -re $prompt
                                                send -- "sudo -l \r"
                                        expect -re $prompt
                                                send -- "$env(remotecom) ; exit\r"
                                        expect -re $prompt
                                                send -- "exit \r"

                                        expect {
                                        "*Permanently added*" {
                                                exp_continue
                                        }
                                        "assword:" {
                                                send "$env(usepas)\r"
                                        } } '

                                        /usr/bin/expect -c '

                                        set timeout 65

                                        spawn ssh $env(username)@$env(nserver) $env(specialcomm)

                                        expect {

                                        "*password*" {
                                                send "$env(usepas)\r"
                                        }
                                        "*yes/no*" {
                                                send "yes\r" ; exp_continue
                                        }
                                        "*password:*" {
                                                send "$env(usepas)\r"
                                        } }'

# 2  
Old 03-26-2016
Is the problem reproducible? Meaning: serverQ always hangs?

What network? An internal LAN or a WAN or the internet? For example, on our comapany-wide network we have points of outage that cause ssh packets to get re-routed, which then causes A man-in-the-middle-attack prompt.

You need to investigate every hang and then code for all possibilities.
This User Gave Thanks to jim mcnamara For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

First script in a long time

I was wondering if I could get some feedback on my script to grab time from our MDM... I blocked out all of the important stuff. I really appreciate any guidance, since I am long out of practice. #!/bin/bash serial=$1 # get last seen value of ipad lastseen=$(curl -s -X "GET"... (11 Replies)
Discussion started by: andysensible
11 Replies

2. Shell Programming and Scripting

Killing the process if running for long time in script

I am running a script which will read the data from fail line by line and call the Java program by providing the arguments from the each line. The Java code is working fast for few records and for some records its getting hanged not providing response for morethan one hour. Currently am... (4 Replies)
Discussion started by: dineshaila
4 Replies

3. Shell Programming and Scripting

Expect script to suspend expecting for a time period.

I have a simple Expect script to power a system on and off in an endless loop looking for an ERROR message at which point the script should exit. But I need to skip the first 60 seconds after each power on or off and not exit if there are ERROR messages during that time. I thought I could use... (0 Replies)
Discussion started by: David_Gilhooly
0 Replies

4. Shell Programming and Scripting

Kill long running script, if it crosses the threshold time

Hi, I need a script to kill the process if it running for long time. Inputs for the scripts: 1.test.sh (will be running fron cron scheduler) 2.1 hr (ie threshold_time - if the test.sh is running for more than 1 hr test.sh has to kill) Thanks, Divya (1 Reply)
Discussion started by: Divya Nochiyil
1 Replies

5. 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

6. Shell Programming and Scripting

help - exec time too long

Dear everyone... thanks to this forum I am able to do everyday more and more complex scripts...but now I come up with problem with optimisation.. problem 1 - optimise: here is my code: while read number do nawk -F "|" -v... (8 Replies)
Discussion started by: abdulaziz
8 Replies

7. Shell Programming and Scripting

<AIX>Problem in purge script, taking very very long time to complete 18.30hrs

Hi, I have here a script which is used to purge older files/directories based on defined purge period. The script consists of 45 find commands, where each command will need to traverse through more than a million directories. Therefore a single find command executes around 22-25 mins... (7 Replies)
Discussion started by: sravicha
7 Replies

8. 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

9. Shell Programming and Scripting

shell script takes long time to complete

Hi all, I wrote this shell script to validate filed numbers for input file. But it take forever to complete validation on a file. The average speed is like 9mins/MB. Can anyone tell me how to improve the performance of a shell script? Thanks (12 Replies)
Discussion started by: ozzman
12 Replies

10. Shell Programming and Scripting

Long time since I used "expect"

Hello all, It's been a few years since I touched 'expect' and just got it on my system. In the past, I could simply do the following: (this is just a simple example) $ expect $ ls -l $ pwd $ exit ...then a default script name would be placed in my working directory. At this point I... (2 Replies)
Discussion started by: scriptosaurus
2 Replies
Login or Register to Ask a Question