cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
545
Views
0
Helpful
3
Replies
james.hayek
Beginner

Minicom Send Return Character

I would like to send the following commands to a 3560-CX 8-Port Switch:

 

enable
interface range GigabitEthernet 0/1-8
power inline static
no cdp enable
exit
exit
copy running-config startup-config

But prior to being able to enter any commands, I must press enter. Can I send a return carriage in a .txt file to pass to a minicom command?

 

I tried '/r' and "/r" which did not work. I also tried a simple expect script:

#!/usr/bin/expect -f
send "\r"

Which also did not work.

The goal is to just call the script like such:

minicom -S testScript.sh #or testScript.txt

Any help is greatly appreciated

3 REPLIES 3
balaji.bandi
VIP Expert

Try this. - change the variable as per your setup.

 

#!/usr/bin/expect -f
set timeout 20
set 10.10.10.1
set Username "username"
set Password "password"
set Directory /home/Desktop/logs
log_file -a /home/debug.log
spawn ssh -o "StrictHostKeyChecking no" $Username@10.10.10.1
expect "*assword: "
send "$Password\r"
expect "#"
send "enable conf t\r"
expect "(config)#"
send "interface range GigabitEthernet 0/1-8 \r"
expect "(config-if-range)#"
send "power inline static \r"
expect "(config-if-range)#"
send "no cdp enable \r"
expect "(config-if-range)#"
send "end"
expect "#"
send "wr mem\r"
expect "#"
send "exit\r"
sleep 1
exit



BB


*** Rate All Helpful Responses ***

Thank you for your help!!

I do have a few questions in regard to the code you posted.

 

I will also comment below the error message I received. I placed comments below each line in your code.

 

 

#!/usr/bin/expect -f
set timeout 20
set 10.10.10.1
set Username "username"
set Password "password

This will be the username and password to login to my RPi running Kali, correct?

set Directory /home/Desktop/logs

I do not have this directory. I have changed the directory to:

/root/Desktop/logs (I made the logs folder using mkdir)

log_file -a /home/debug.log

Does this command create a log file named debug.log?

I changed the path to: /root/debug.log (there is no .log file in the directory even after I run the script)

spawn ssh -o "StrictHostKeyChecking no" $Username@10.10.10.1
expect "*assword: "
send "$Password\r"
expect "#"

Is there supposed to be a space after the colon? 

send "enable conf t\r"

It is at this point that I saved the .sh file and called it using minicom. I wanted to see if the switch> prompt would turn to switch# but it did not.

 

I actually got the error: "script "testScript.sh" line 4: unknown variable "root"

 

Any advice?

Thanks again for your help!

 

One of post with more details - hope this helps you.

 

http://www.balajibandi.com/2015/10/03/cisco-automate-the-config-with-expect-command/



BB


*** Rate All Helpful Responses ***

Content for Community-Ad

This widget could not be displayed.