Reboot Loop
The snippet can be accessed without any authentication.
Authored by
Nico
Script to reboot devices in a loop over serial console. This can help to identify reboot issues.
rebootloop.py 658 B
#!/usr/bin/python3
import serial
import pexpect
import pexpect.fdpexpect
import sys
import re
import time
import random
prompt = "root@[^:]+"
serial = serial.Serial()
serial.baudrate = 115200
serial.port = "/dev/ttyUSB0"
serial.open()
def activate_console(p):
p.sendline("")
p.expect(prompt)
p = pexpect.fdpexpect.fdspawn(serial, logfile=sys.stdout, encoding="UTF-8")
p.sendline("")
bootcount = 0
while True:
i = p.expect(["Please press Enter to activate this console.", prompt])
if i == 0:
activate_console(p)
print(f"Boot #{bootcount}")
time.sleep(random.randrange(3, 180))
p.sendline("reboot -f")
bootcount+=1
Please register or sign in to comment