ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.