mirror of
https://github.com/wickedyoda/public-setupfiles.git
synced 2026-11-16 13:31:56 -06:00
commit
1e25e36ce6
195 files changed
+152301
No files matched your search
@@ -0,0 +1,45 @@
|
||||
<<<<<<< HEAD
|
||||
# system_command_run
|
||||
|
||||
## Purpose
|
||||
This directory contains files related to **system command run**.
|
||||
|
||||
## Contents
|
||||
- `machines.txt`
|
||||
- `run_command_on_machines_Keys.py'`
|
||||
- `Run_command_on_machines.sh`
|
||||
- `run_command_on_machines.py'`
|
||||
|
||||
## Usage
|
||||
- Review each script or configuration file before running
|
||||
- Some scripts may require **root or sudo**
|
||||
- Paths and variables may need adjustment for your environment
|
||||
|
||||
## Notes
|
||||
- This folder is part of the **public-setupfiles** repository
|
||||
- Files are provided as-is for reference or automation
|
||||
|
||||
## Safety
|
||||
Always back up data before running scripts that modify system state.
|
||||
=======
|
||||
# system_command_run
|
||||
|
||||
## Overview
|
||||
This directory is part of the **public-setupfiles** repository.
|
||||
It contains scripts, configuration files, or resources related to **system_command_run**.
|
||||
|
||||
## Usage
|
||||
- Review scripts before execution
|
||||
- Some files may require **root or sudo privileges**
|
||||
- Paths, variables, or credentials may need customization
|
||||
|
||||
## Logging & Output
|
||||
Scripts may generate logs or output files in the same directory or system locations.
|
||||
|
||||
## Safety Notes
|
||||
- Always back up important data before running scripts
|
||||
- Test in a non-production environment when possible
|
||||
- Use at your own risk
|
||||
|
||||
---
|
||||
>>>>>>> main
|
||||
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
|
||||
MACHINE_FILE="machines.txt"
|
||||
LOG_FILE="ssh_command_log.txt"
|
||||
|
||||
echo -n "Enter command to execute: "
|
||||
read COMMAND
|
||||
|
||||
echo "Executing on all machines..."
|
||||
echo "Execution Log - $(date)" > "$LOG_FILE"
|
||||
|
||||
while IFS=" " read -r HOST USER PASS; do
|
||||
echo "Running on $HOST..."
|
||||
if [[ -z "$PASS" ]]; then
|
||||
ssh "$USER@$HOST" "$COMMAND" >> "$LOG_FILE" 2>&1
|
||||
else
|
||||
sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no "$USER@$HOST" "$COMMAND" >> "$LOG_FILE" 2>&1
|
||||
fi
|
||||
done < "$MACHINE_FILE"
|
||||
|
||||
echo "Execution complete. Logs saved in $LOG_FILE."
|
||||
@@ -0,0 +1 @@
|
||||
docker1 root
|
||||
Whitespace-only changes.
@@ -0,0 +1,30 @@
|
||||
def execute_command(hostname, username, command):
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
|
||||
try:
|
||||
ssh.connect(hostname, username=username, key_filename="~/.ssh/id_rsa", timeout=5)
|
||||
stdin, stdout, stderr = ssh.exec_command(command)
|
||||
output = stdout.read().decode().strip()
|
||||
error = stderr.read().decode().strip()
|
||||
|
||||
with open(LOG_FILE, "a") as log:
|
||||
log.write(f"----- {hostname} ({username}) -----\n")
|
||||
log.write(f"Command: {command}\n")
|
||||
log.write(f"Output:\n{output}\n")
|
||||
if error:
|
||||
log.write(f"Errors:\n{error}\n")
|
||||
log.write("\n")
|
||||
|
||||
print(f"[{hostname}] Command executed successfully.")
|
||||
if error:
|
||||
print(f"[{hostname}] ERROR: {error}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"[{hostname}] Connection failed: {e}")
|
||||
with open(LOG_FILE, "a") as log:
|
||||
log.write(f"----- {hostname} ({username}) -----\n")
|
||||
log.write(f"ERROR: {e}\n\n")
|
||||
|
||||
finally:
|
||||
ssh.close()
|
||||
Reference in new issue
Block a user