Hi everybody,<br><br>I hope i'm in the right place. I'm trying to automate an operation we usually do manually with some RS232(serial port)/ethernet MOXA switches.<br>This operation reboots a linux debian device by sending a "magic-sysrq+b" command to the kernel if this device does not respond through SSH.<br>
To do that manually, we do :<br># this is the connection to the RS/232-ethernet port, this switch is connected with the linux device through a serial port<br># and connected to my LAN with an ethernet cable. The switch serial port 1 is bound to tcp port 100.<br>
alex@jazz:~$ telnet 10.1.1.1 100<br>Trying 10.1.1.1 ...<br>Connected to 10.1.1.1.<br>Escape character is '^]'.<br># here, i can press "enter" to access to the linux prompt <br># or i can enter "ctrl+]" to access the telnet prompt<br>
# here, i enter "ctrl + ]" and get the switch prompt<br>telnet><br># now i enter "send brk" then "enter", this is the same thing than the linux "magic sysrq"<br>telnet> send brk<br>
# now i press "b" (without enter), then the device directly "hard reboot" with a short message like "resetting system"<br><br>So, i want to do this with pexpect, here is my script : <br>-------------------------------<br>
import pexpect <br>import sys <br>import time <br>
import os <br> <br>switch_ip_address = sys.argv[1]<br>
switch_port = sys.argv[2] <br>sysrq_key = sys.argv[3] <br><br>print('ip address is: ' + switch_ip_address) <br>
print('switch port number is: ' + switch_port) <br>print('sysrq key is: ' + sysrq_key) <br><br>telnet_child = pexpect.spawn('telnet ' + switch_ip_address + ' ' + switch_port) <br>
telnet_child.expect('Escape.*')<br>telnet_child.sendcontrol(']')<br>telnet_child.expect('telnet> ')<br>telnet_child.sendline('send brk')<br>#time.sleep(0.5)<br>telnet_child.send(sysrq_key)<br>
-------------------------------<br>It looks like it is working almost fine, when i run my script with : <br>python send_brk.py 10.1.1.1 100 b<br>the script end without errors.<br>Then i connect to the switch to check if the device has rebooted but it has not :<br>
-------------------------------<br>athaveau@athaveau:~$ telnet 10.1.1.1 100<br>Trying 10.1.1.1...<br>Connected to 10.1.1.1.<br>Escape character is '^]'.<br>-------------------------------<br>Then when i press enter, i get that : <br>
-------------------------------<br>SysRq : HELP : loglevel0-8 reBoot tErm Full kIll show-backtrace-all-active-cpus(L) showMem Nice showPc Sync showTasks Unmount showLocks <br>-------------------------------<br>this is the magic sysrq helper, so it looks like the last thing i sent: the "b" (sysrq_key variable) letter is not sent to the<br>
telnet command but i can't understand why.<br>I know this is a long and certainly a little bit boring :-) but if someone has an idea ... it would very pleasant !<br><br>Thanks by advance.<br><br><br>