Community discussions

MikroTik App
 
Syonyk
Member Candidate
Member Candidate
Topic Author
Posts: 109
Joined: Mon Feb 14, 2005 6:32 pm
Location: Coralville, IA
Contact:

Expect isn't working properly - it's not sending commands.

Wed May 18, 2005 12:45 am

I've tried quite a few expect scripts to remotely work on our Mikrotiks, and they seem to be avoiding sending data.
#!/usr/bin/expect
#
spawn /usr/bin/ssh 1.2.3.4 -l admin
expect -re "password:"
send "password\r"
#
expect ">"
send  "system resource print\n"
sleep 2
#
expect -re "] > "
send "print"
I've also tried several other scripts, including YazzY's script. They all show the exact same thing: They log into the Mikrotik properly, and then accomplish nothing. I see no commands or responses sent, and the Mikrotik logs out.

I've tried pointing the script at a local Linux server, and it works properly - I see the commands & responses.

Ideas?

-=Russ=-
 
jarosoup
Long time Member
Long time Member
Posts: 600
Joined: Sun Aug 22, 2004 9:02 am

Wed May 18, 2005 3:48 am

You might need to manually login once first from the box running the script via ssh as the user your script uses in order to accept the cert...it will prompt for a yes/no the first time you login.
 
Syonyk
Member Candidate
Member Candidate
Topic Author
Posts: 109
Joined: Mon Feb 14, 2005 6:32 pm
Location: Coralville, IA
Contact:

Wed May 18, 2005 5:00 am

I've already taken care of that - it logs in successfully, just... doesn't do anything after that. I get the full banner and prompt, but that's it.

-=Russ=-
 
User avatar
tneumann
Member
Member
Posts: 394
Joined: Sat Apr 16, 2005 6:38 pm
Location: Germany

Wed May 18, 2005 2:49 pm

Try to end the commands that you send with \r instead of \n just like you do when you send the password.

--Tom
 
Syonyk
Member Candidate
Member Candidate
Topic Author
Posts: 109
Joined: Mon Feb 14, 2005 6:32 pm
Location: Coralville, IA
Contact:

Wed May 18, 2005 4:44 pm

Try to end the commands that you send with \r instead of \n just like you do when you send the password.

--Tom
Eh, yea. Should have specified above. I've tried \n, \r, \r\n, \n\r, pretty much everything I can think of.

Just to confirm, I should be able to see the output coming back when I run the commands, correct? I see the login prompts & banner, so it would make sense to me that I see the output from the commands I'm running.

-=Russ=-
 
Syonyk
Member Candidate
Member Candidate
Topic Author
Posts: 109
Joined: Mon Feb 14, 2005 6:32 pm
Location: Coralville, IA
Contact:

Thu May 19, 2005 6:42 pm

My old script still isn't working, but I was able to create something that worked with autoexpect and then trim it down to work.
#!/usr/bin/expect -f

spawn ssh 1.2.3.4 -l admin
expect "admin@1.2.3.4's password: "
send -- "password\r"
expect " > "
send -- "system resource print\r"
expect " > "
send -- "queue simple print\r"
expect " > "
send -- "quit\r"
expect eof 
This works properly for some reason, and my other one didn't.

Anyway, apparently, if you're having trouble, try using autoexpect to log a session & then tweak it's output.

-=Russ=-

Who is online

Users browsing this forum: Baidu [Spider], sheo3e and 34 guests