BarbaricBoot Is die Mass Reboot Tool Jou IT-afdeling het dit nie geweet nie

deur barberion4m2025/07/09
Read on Terminal Reader

Te lank; Om te lees

BarbaricBoot is 'n kommando-lyn Python-skript wat 'n lys van rekenaarname lees en parallelle herstart op hulle vrystel. Dit maak gebruik van multi-threading vir maksimum doeltreffendheid.
featured image - BarbaricBoot Is die Mass Reboot Tool Jou IT-afdeling het dit nie geweet nie
barberion HackerNoon profile picture
0-item

Die bestuur van 'n moderne korporatiewe omgewing kan selfs die moeilikste IT-oorloggers versuim - veral wanneer jy 'n vloot van koppige eindpunte moet herstart.BarbaricBoot, 'n Python-aangedrewe massa herstart gereedskap, ontwerp vir beheerders wat nie tyd het vir klik-by-klik-monotonie nie. Soos 'n ware Barberion, sny dit deur jou lys van masjiene met spoed, krag en nul geduld vir hindernisse.

Wat is die BarbaricBoot?

BarbaricBootis 'n command-line Python script wat 'n lys van rekenaar name lees en parallelle herstart op hulle vryskut, rapporteer elke oorwinning en nederlaag langs die pad. Perfect vir Windows-sentrieke omgewings (dank aan sy gebruik van dieshutdownElke mislukte herstart word geregistreer - elke suksesvolle herstart is nog 'n gewende stryd.

Hoekom die barbarisme?

  • Effektiviteit: Herstart honderde masjiene in minute, nie ure nie.
  • Eenvoudigheid: Een lêer, een bevel, minimale instelling.
  • Aanspreekbaarheid: Real-time terugvoer oor sukses en mislukkings.
  • No-Nonsense Barbarian Spirit: Net herstart hulle almal - geen verskonings nie, geen genade nie.

Hoe dit werk

  1. Invoer: Drop jou masjien name (een per lyn) in pcs.log.
  2. Uitvoering: BarbaricBoot aanvalle gebruik Python se concurrent.futures om tot 20 parallelle herstarts op 'n keer te begin.
  3. Feedback: Jy kry real-time tellings van sukses en mislukking - plus gedetailleerde logboeke van enige masjiene wat jou bevel weier.

Hoe om te installeer en gebruik BarbaricBoot

Die vereistes

  • Python 3.6 of nuwer
  • Windows-administratiewe bevoegdhede (vir remote shutdown regte)
  • 'N pcs.log-lêer met 'n lys van jou doelmasjiene (een per lyn)

Stel

  1. **Save the Script \ Copy the complete BarbaricBoot.py code (provided below) to your admin machine.
  2. **Prepare Your Targets \ Create a plain text file called pcs.log in the same directory as your script, listing each machine to be rebooted.
  3. **Run BarbaricBoot \ Open a terminal and execute: “Python BarbericBoot.py“

Die volledige kode

#Another        /\_[]_/\
#    fine      |] _||_ [|
#       ___     \/ || \/
#      /___\       ||
#     (|0 0|)      ||
#   __/{\U/}\_ ___/vvv
#  / \  {~}   / _|_P|
#  | /\  ~   /_/   []
#  |_| (____)        
#  \_]/______\  Barberion  
#     _\_||_/_     Production      
#    (_,_||_,_)
#
import concurrent.futures
import subprocess
import logging
from threading import Lock

# Set up logging for failed reboots
logging.basicConfig(filename='failed_reboots.log', level=logging.INFO)

# Lock for thread-safe printing and updating counters
print_lock = Lock()

def reboot_machine(machine_name, success_counter, failure_counter):
    try:
        subprocess.run(['shutdown', '/r', '/t', '0', '/m', f'\\\\{machine_name}', '/f'], 
                       check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        with print_lock:
            success_counter[0] += 1
            print(f"\rTotal successful reboots: {success_counter[0]}, Total failed reboots: {failure_counter[0]}", end='')
    except subprocess.CalledProcessError as e:
        with print_lock:
            failure_counter[0] += 1
            print(f"\rTotal successful reboots: {success_counter[0]}, Total failed reboots: {failure_counter[0]}", end='')
        logging.error(f"Failed to reboot {machine_name}: {e}")

def main():
    with open('pcs.log') as file:
        machines = file.readlines()

    total_hosts = len(machines)
    print(f"Total hosts in file: {total_hosts}")

    # Shared counters for successful and failed reboots
    successful_reboots = [0]
    failed_reboots = [0]

    # Use ThreadPoolExecutor for parallel execution
    with concurrent.futures.ThreadPoolExecutor(max_workers=20) as executor:
        futures = [executor.submit(reboot_machine, machine.strip(), successful_reboots, failed_reboots) for machine in machines]

        # Wait for all tasks to complete, i suppose you can  comment out for rapid fire.
        concurrent.futures.wait(futures)

    # Final print to ensure the last count is displayed correctly
    print(f"\nFinal count - Total successful reboots: {successful_reboots[0]}, Total failed reboots: {failed_reboots[0]}")

if __name__ == "__main__":
    main()

Customiseer Tips

  • Verhoog of Verminder Parallelisme: Tweak max_workers=20 vir meer of minder parallelle aanvalle, afhangende van jou omgewing se verdraagsaamheid.
  • Log: Alle mislukte pogings word in failed_reboots.log gestoor vir latere hersiening.
  • Vinnig Vuur Opsie: Kommentaar uit die concurrent.futures.wait(futures) lyn as jy wil om die script uit te laat en te beweeg

Laaste gedagtes

BarbaricBoot is nie vir die skaamte nie. Gebruik dit verantwoordelik, gebruik dit verstandig, en onthou: met groot krag kom groot verantwoordelikheid. Mag jou herstartings vinnig wees, jou logs skoon, en jou eindpunte altyd-voldoende!

Trending Topics

blockchaincryptocurrencyhackernoon-top-storyprogrammingsoftware-developmenttechnologystartuphackernoon-booksBitcoinbooks