expect minicom

Hi,

I am new to using minicom. I want how to write a expect script for minicom login? I wrote a code but its not acting what iam expecting. here I have my code:

#!/usr/bin/expect

set fd [ open /dev/ttyUSB1 { RDWR NONBLOCK } ]

fconfigure $fd

spawn -open $fd

  spawn minicom
expect �enter:�
send "\n"
send "\n"


expect \
"Valiant login: " {
exp_send "username\n"
exp_continue
} "Password: " {
exp_send "password\n"
exp_continue
}

Response for above code:

spawn [open ...]
spawn minicom

Welcome to minicom 2.4

OPTIONS: I18n 
Compiled on Jun  3 2010, 13:46:31.
Port /dev/ttyS0

Press CTRL-A Z for help on special keys

Error CLI cmd Not Found !


ETH-T1>
ETH-T1>root@vani:~# 

but here I want output like:
it should show my login and password message which is sent from my hardware but it is jumping without showing it directly to my command line and existing from that session (login) . I dont want to exit from the login session

Is their any problem in my code: please do suggest me thank you

---------- Post updated at 05:20 AM ---------- Previous update was at 03:10 AM ----------

Actual what iam expecting is:
i am trying to write a script to logon to a system using minicom.
when I do minicom in my shell...
i want screen as below:

Welcome to minicom 2.4

OPTIONS: I18n
Compiled on Jun 3 2010, 13:46:31.
Port /dev/ttyS0

Press CTRL-A Z for help on special keys

=========== ===========

          Welcome to System Manager

System Configuration:
PROCESSOR : ARM926ej-s @ 398 MHz
RAM : 64 MBytes, DDR-1
FLASH : 512 MBytes, HYNIX SLC
OPERATING SYSTEM: GNULinux 2.6.31

Valiant login: username
Password: password

==============================
but...........

  • my problem is iam not able to see the screen as above for login instead it gives as below

==============================
Welcome to minicom 2.4

OPTIONS: I18n
Compiled on Jun 3 2010, 13:46:31.
Port /dev/ttyS0

Press CTRL-A Z for help on special keys

username
Unknown OAM Command:"username"

ETH-T1>password
Cant accept reserved characters in your command

ETH-T1>
ETH-T1>$$config/oam
Unknown OAM Command:"$$config/oam"

==============================
My commands are:

#!/usr/local/bin/expect �f
log_file -noappend logfile_telnet
set timeout 2
set user "username"
set password "password"
spawn minicom
expect "enter:"
send ""

expect "login:\r"
send "$user\r "
expect "Password:\r"
send "$password\r"
expect "$ " #passing command after login
send "\$\$config/oam\r"

when i do a spawn telnet instead of this the script runs fine........

thank you

Why not use the serial port direct?

exec 5</dev/ttyS1
exec 6>/dev/ttyS1

read LINE <&5
echo "hello" >&6

You may need to set up the port correctly with stty first. You can set up timeouts if you want to try something fancy.

I suppose you could redirect it into expect, too.

Thank you.

I will try it but i didnt get the line you said " I suppose you could redirect it into expect too." please can you eleborate more clearly as iam very new to expect and as well to minicom.

Thanks again

Well, just that. Redirect stdin from the comport and stdout to the com port. How to do so depends on how you're using expect.