LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-08-2009, 04:59 PM   #1
fbasma
LQ Newbie
 
Registered: Oct 2009
Location: USA/OKlahoma
Posts: 7

Rep: Reputation: 0
Expect reliable ?


hello all,

i'm having some reliability problem with expect, what i'm trying to do is basically go to all the computers on the network and do an update to all of them. so i have two codes;

1-bash script --> get all ip address , for each run expect command
2- expect script to do the update

the problem i'm having is for about 90 % of the ip addresses the expect works fine however for the rest for some reason it doesn't, the password that i supply will just pop up and it would not take it.

i really hope that i make sense, let me know if you need any other info,

the code is below:

thanks in advance.


//bash script

LIST=`ifconfig | awk '/P-t-P/ {print $3}' | cut -c 7-20 | sort`
for ip in $LIST
do
echo $ip >> check.txt
./update2 $1 $ip $2 >> check.txt
sleep 1
done
exit

//expect program "update2"

set password [lindex $argv 2]
set ip [lindex $argv 1]
spawn /usr/bin/scp or ssh " basically do the update"
sleep 1
expect "password:"
send "$password\r"
expect eof
 
Old 10-09-2009, 06:18 AM   #2
carltm
Member
 
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 703

Rep: Reputation: 99
Try removing the "sleep 1" in update2. It's possible that the
password prompt is being sent before the expect "password:" line
is executed.
 
Old 10-09-2009, 09:05 PM   #3
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Put exp_internal 1 as the first line in your program. Without it, you'll never be able to figure out what your spawned program sends to you and how the output is being interpreted by Expect.

Expect is reliable, I have some Expect scripts running in a process controller and they spawn telnet and snmp programs. Some of them once every second, 24/7 for months already.

So I think you didn't mean to ask if Expect is reliable, but rather what unexpected (no pun intended) could be happening.

jlinkels
 
Old 10-10-2009, 12:07 AM   #4
fbasma
LQ Newbie
 
Registered: Oct 2009
Location: USA/OKlahoma
Posts: 7

Original Poster
Rep: Reputation: 0
Fixed

Thanks guys,

Actually i kind of figured it out, as usual i kind of rushed into conclusions without doing what i'm supposed to do (more debuggin) , it seems that i have to sleep more than 1 sec, because in my setup the network connection for each location (IPs) differs from one another. for example if the network connection is bad, it will take more time to ssh --> need more time to expect a password. i increased the sleep to 4 seconds and it worked.

Thanks again guys , appreciate your help

Last edited by fbasma; 10-10-2009 at 12:08 AM.
 
Old 10-10-2009, 07:06 AM   #5
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Expect knows how to handle timeouts. Check the timeout statement.

jlinkels
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Expect script: how do i send function key F12 in an expect script alix123 Programming 4 09-01-2013 09:06 PM
is VirtualBox reliable? newbiesforever Linux - Software 8 09-15-2008 05:54 AM
Calling expect scripts from other expect scripts sevapopov Linux - Software 3 04-03-2008 09:33 PM
telnet server not reliable for expect script powah Linux - Software 0 11-16-2005 11:07 AM
How reliable are ........ phatbastard Linux - Security 1 12-13-2004 10:30 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration