expect not taking ssh arguments in while/for loop

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I'm trying to fetch remote machine details (dmidecode) for many hosts using some expect command.
Below is the expect script which I'm using for this purpose.
while read i; do
/usr/bin/expect<<EOF
spawn ssh "root@$i" dmidecode
expect "Password:"
send "xxxxr";
interact
EOF
done<iplist
But here command which is not excecuting on the remote machine. I tried with single, double quotes and caret symbol still no luck.
Here I want to execute remote command as argument like : ssh <ip> <remote command>
Please shed me some views, I might be missed some params here, please help me
bash ssh expect
add a comment |Â
up vote
1
down vote
favorite
I'm trying to fetch remote machine details (dmidecode) for many hosts using some expect command.
Below is the expect script which I'm using for this purpose.
while read i; do
/usr/bin/expect<<EOF
spawn ssh "root@$i" dmidecode
expect "Password:"
send "xxxxr";
interact
EOF
done<iplist
But here command which is not excecuting on the remote machine. I tried with single, double quotes and caret symbol still no luck.
Here I want to execute remote command as argument like : ssh <ip> <remote command>
Please shed me some views, I might be missed some params here, please help me
bash ssh expect
2
The finalEOFmay not be preceded by a space character. I'm not 100% certain that's the only error since I'm not used toexpect. The...may be removed in any case.
â Kusalananda
Jun 22 at 15:18
take a look at sexpect with which you can write "Expect" scripts with shell code only and you don't have to learn the Tcl/Expect language.
â pynexj
Jun 22 at 15:43
Try adding a-noption to thesshcommand.
â Mark Plotnick
Jul 8 at 15:18
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm trying to fetch remote machine details (dmidecode) for many hosts using some expect command.
Below is the expect script which I'm using for this purpose.
while read i; do
/usr/bin/expect<<EOF
spawn ssh "root@$i" dmidecode
expect "Password:"
send "xxxxr";
interact
EOF
done<iplist
But here command which is not excecuting on the remote machine. I tried with single, double quotes and caret symbol still no luck.
Here I want to execute remote command as argument like : ssh <ip> <remote command>
Please shed me some views, I might be missed some params here, please help me
bash ssh expect
I'm trying to fetch remote machine details (dmidecode) for many hosts using some expect command.
Below is the expect script which I'm using for this purpose.
while read i; do
/usr/bin/expect<<EOF
spawn ssh "root@$i" dmidecode
expect "Password:"
send "xxxxr";
interact
EOF
done<iplist
But here command which is not excecuting on the remote machine. I tried with single, double quotes and caret symbol still no luck.
Here I want to execute remote command as argument like : ssh <ip> <remote command>
Please shed me some views, I might be missed some params here, please help me
bash ssh expect
edited Jun 22 at 17:36
Ouki
3,58021324
3,58021324
asked Jun 22 at 15:00
jay
61
61
2
The finalEOFmay not be preceded by a space character. I'm not 100% certain that's the only error since I'm not used toexpect. The...may be removed in any case.
â Kusalananda
Jun 22 at 15:18
take a look at sexpect with which you can write "Expect" scripts with shell code only and you don't have to learn the Tcl/Expect language.
â pynexj
Jun 22 at 15:43
Try adding a-noption to thesshcommand.
â Mark Plotnick
Jul 8 at 15:18
add a comment |Â
2
The finalEOFmay not be preceded by a space character. I'm not 100% certain that's the only error since I'm not used toexpect. The...may be removed in any case.
â Kusalananda
Jun 22 at 15:18
take a look at sexpect with which you can write "Expect" scripts with shell code only and you don't have to learn the Tcl/Expect language.
â pynexj
Jun 22 at 15:43
Try adding a-noption to thesshcommand.
â Mark Plotnick
Jul 8 at 15:18
2
2
The final
EOF may not be preceded by a space character. I'm not 100% certain that's the only error since I'm not used to expect. The ... may be removed in any case.â Kusalananda
Jun 22 at 15:18
The final
EOF may not be preceded by a space character. I'm not 100% certain that's the only error since I'm not used to expect. The ... may be removed in any case.â Kusalananda
Jun 22 at 15:18
take a look at sexpect with which you can write "Expect" scripts with shell code only and you don't have to learn the Tcl/Expect language.
â pynexj
Jun 22 at 15:43
take a look at sexpect with which you can write "Expect" scripts with shell code only and you don't have to learn the Tcl/Expect language.
â pynexj
Jun 22 at 15:43
Try adding a
-n option to the ssh command.â Mark Plotnick
Jul 8 at 15:18
Try adding a
-n option to the ssh command.â Mark Plotnick
Jul 8 at 15:18
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
One simplification would be to eliminate the buggy and slow shell while loop which would also free up stdin to be used for interact. That is, the input file would instead be passed to and read by TCL code in the expect script.
#!/usr/bin/expect
if [llength $argv] != 1
puts stderr "Usage: $0 iplist-file"
exit 1
set ipfh [open [lindex $argv 0]]
while [gets $ipfh ip] >= 0
spawn ssh root@$ip dmidecode
expect "Password:"
send "Hunter2r";
interact
add a comment |Â
up vote
1
down vote
thrig has a great answer. If you want to stick with bash (even though the while-read loop is extremely slow, and tedious to get right syntax-wise), use a different file descriptor to read from the file and allow expect to hold onto stdin:
while IFS= read -r -u3 ip; do
# .................^^^
/usr/bin/expect << EOF
spawn ssh "root@$ip" dmidecode
expect "Password:"
send "xxxxr";
interact
EOF
done 3< iplist
# ...^^
If the dmidecode command does not require human interaction, change interact to expect eof
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
One simplification would be to eliminate the buggy and slow shell while loop which would also free up stdin to be used for interact. That is, the input file would instead be passed to and read by TCL code in the expect script.
#!/usr/bin/expect
if [llength $argv] != 1
puts stderr "Usage: $0 iplist-file"
exit 1
set ipfh [open [lindex $argv 0]]
while [gets $ipfh ip] >= 0
spawn ssh root@$ip dmidecode
expect "Password:"
send "Hunter2r";
interact
add a comment |Â
up vote
2
down vote
One simplification would be to eliminate the buggy and slow shell while loop which would also free up stdin to be used for interact. That is, the input file would instead be passed to and read by TCL code in the expect script.
#!/usr/bin/expect
if [llength $argv] != 1
puts stderr "Usage: $0 iplist-file"
exit 1
set ipfh [open [lindex $argv 0]]
while [gets $ipfh ip] >= 0
spawn ssh root@$ip dmidecode
expect "Password:"
send "Hunter2r";
interact
add a comment |Â
up vote
2
down vote
up vote
2
down vote
One simplification would be to eliminate the buggy and slow shell while loop which would also free up stdin to be used for interact. That is, the input file would instead be passed to and read by TCL code in the expect script.
#!/usr/bin/expect
if [llength $argv] != 1
puts stderr "Usage: $0 iplist-file"
exit 1
set ipfh [open [lindex $argv 0]]
while [gets $ipfh ip] >= 0
spawn ssh root@$ip dmidecode
expect "Password:"
send "Hunter2r";
interact
One simplification would be to eliminate the buggy and slow shell while loop which would also free up stdin to be used for interact. That is, the input file would instead be passed to and read by TCL code in the expect script.
#!/usr/bin/expect
if [llength $argv] != 1
puts stderr "Usage: $0 iplist-file"
exit 1
set ipfh [open [lindex $argv 0]]
while [gets $ipfh ip] >= 0
spawn ssh root@$ip dmidecode
expect "Password:"
send "Hunter2r";
interact
answered Jun 22 at 15:17
thrig
21.8k12751
21.8k12751
add a comment |Â
add a comment |Â
up vote
1
down vote
thrig has a great answer. If you want to stick with bash (even though the while-read loop is extremely slow, and tedious to get right syntax-wise), use a different file descriptor to read from the file and allow expect to hold onto stdin:
while IFS= read -r -u3 ip; do
# .................^^^
/usr/bin/expect << EOF
spawn ssh "root@$ip" dmidecode
expect "Password:"
send "xxxxr";
interact
EOF
done 3< iplist
# ...^^
If the dmidecode command does not require human interaction, change interact to expect eof
add a comment |Â
up vote
1
down vote
thrig has a great answer. If you want to stick with bash (even though the while-read loop is extremely slow, and tedious to get right syntax-wise), use a different file descriptor to read from the file and allow expect to hold onto stdin:
while IFS= read -r -u3 ip; do
# .................^^^
/usr/bin/expect << EOF
spawn ssh "root@$ip" dmidecode
expect "Password:"
send "xxxxr";
interact
EOF
done 3< iplist
# ...^^
If the dmidecode command does not require human interaction, change interact to expect eof
add a comment |Â
up vote
1
down vote
up vote
1
down vote
thrig has a great answer. If you want to stick with bash (even though the while-read loop is extremely slow, and tedious to get right syntax-wise), use a different file descriptor to read from the file and allow expect to hold onto stdin:
while IFS= read -r -u3 ip; do
# .................^^^
/usr/bin/expect << EOF
spawn ssh "root@$ip" dmidecode
expect "Password:"
send "xxxxr";
interact
EOF
done 3< iplist
# ...^^
If the dmidecode command does not require human interaction, change interact to expect eof
thrig has a great answer. If you want to stick with bash (even though the while-read loop is extremely slow, and tedious to get right syntax-wise), use a different file descriptor to read from the file and allow expect to hold onto stdin:
while IFS= read -r -u3 ip; do
# .................^^^
/usr/bin/expect << EOF
spawn ssh "root@$ip" dmidecode
expect "Password:"
send "xxxxr";
interact
EOF
done 3< iplist
# ...^^
If the dmidecode command does not require human interaction, change interact to expect eof
answered Jun 22 at 15:28
community wiki
glenn jackman
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f451326%2fexpect-not-taking-ssh-arguments-in-while-for-loop%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
The final
EOFmay not be preceded by a space character. I'm not 100% certain that's the only error since I'm not used toexpect. The...may be removed in any case.â Kusalananda
Jun 22 at 15:18
take a look at sexpect with which you can write "Expect" scripts with shell code only and you don't have to learn the Tcl/Expect language.
â pynexj
Jun 22 at 15:43
Try adding a
-noption to thesshcommand.â Mark Plotnick
Jul 8 at 15:18