LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   combine bash & expect with variable from user input (https://www.linuxquestions.org/questions/linux-newbie-8/combine-bash-and-expect-with-variable-from-user-input-755883/)

ndnd 09-17-2009 07:20 AM

combine bash & expect with variable from user input
 
hi all

I've tried to combine bash script and expect without any success...
can someone point me what is wrong here ?

#!/bin/bash
rm -rf /tmp/*log*
expect -c "
spawn /usr/bin/ssh -l username [lindex $argv 0]\n
expect )?
send yes\n
expect password:
send password\n
expect "Server"
send "print os date\n"
expect "is"
send "print os time\n"
"
sed -i 's/\r$//g' log
cat /tmp/log
exit
------------
here's the output i get when i run :
#./myscript 10.10.10.1 > log

without redirect to log file it look like this :
spawn /usr/bin/ssh -l username 0

The authenticity of host '0
(0.0.0.0)' can't be established.
RSA key fingerprint is 2c:6e:2a:d6:d0:43:73:06:95:be:82:8e:83:1d:a1:cf.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '0
' (RSA) to the list of known hosts.
username@0
's password:
Permission denied, please try again.


10x.

linuxlover.chaitanya 09-17-2009 07:25 AM

Is not 0.0.0.0 a strange address and it will mean all the addresses available?

ndnd 09-17-2009 09:18 AM

if i'm using only expect script , it works just fine :

#!/usr/bin/expect
spawn /usr/bin/ssh -l username [lindex $argv 0]\n
expect )?
send yes\n
expect password:
send password\n
expect "Server"
send "print os date\n"
expect "is"
send "print os time\n"
"
sed -i 's/\r$//g' log
cat /tmp/log
exit

but i need to run some other commands that's why I want to include bash inside and i don't wanna use multiple script files for that.


All times are GMT -5. The time now is 08:02 PM.