Skip to content
Snippets Groups Projects

Reboot Loop

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    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.

    Edited
    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
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment