Sunday, March 16, 2025

Automate Remote Script Execution with rconf

Programming LanguageAutomate Remote Script Execution with rconf


Introduction

Managing remote servers efficiently is crucial for system administrators and DevOps teams. rconf is a powerful command-line tool that simplifies running local shell scripts across multiple remote hosts via SSH. It eliminates the need for complex configurations, providing a lightweight and efficient way to execute scripts remotely with just a single binary.


🚀 Key Features

  • Concurrent Execution: Execute scripts on multiple hosts simultaneously with configurable concurrency levels.
  • Structured Logging: Provides detailed logs to aid in monitoring and troubleshooting.
  • Secure Authentication: Uses SSH private keys for secure connections, supporting password-protected keys.
  • Automatic Script Management: Uploads and executes scripts on remote hosts seamlessly.
  • Execution Summary: Displays a summary table of execution results.

📥 Installation

1️⃣ Manual Installation

  1. Download the latest binary from the Releases page.
  2. Place the binary in your system’s PATH (e.g., /usr/local/bin).
  3. Ensure it has executable permissions:
   chmod +x /usr/local/bin/rconf
Enter fullscreen mode

Exit fullscreen mode

2️⃣ Homebrew Installation (macOS)

brew tap hashmap-kz/rconf
brew install rconf
Enter fullscreen mode

Exit fullscreen mode


🛠 Usage Example

rconf \
  --pkey /path/to/private_key \
  --filename /path/to/script1.sh,/path/to/script-dir/ \
  --filename https://shared.company.com/path/to/script.sh \
  --conn backup@10.40.240.193 \
  --conn myuser@10.40.240.189:2222 \
  --workers 5 \
  --log execution.log
Enter fullscreen mode

Exit fullscreen mode


🔍 CLI Flags Overview

Flag Short Description
--pkey -i Path to SSH private key (required).
--pkey-pass Passphrase for SSH private key (if password-protected).
--filename -f Comma-separated list of scripts, directories, or URLs.
--conn -H List of remote hosts (username:password@host:port).
--recursive -R Process directories recursively (default: true).
--workers -w Maximum concurrent SSH connections (default: 2).
--log -l Log file path (default: ssh_execution.log).

🔧 How It Works

  1. Reads the specified scripts into memory.
  2. Establishes SSH and SFTP connections to remote hosts.
  3. Uploads scripts to the remote /tmp/ directory.
  4. Executes scripts remotely using sudo.
  5. Stores and displays execution results in a structured summary.

📊 Example Output

🚀 Starting script execution...
[HOST: 10.40.240.189] 🔄 Connecting...
[HOST: 10.40.240.193] 🔄 Connecting...
[HOST: 10.40.240.193] ⏳ Uploading scripts\00-packages.sh...
[HOST: 10.40.240.193] 🚀 Executing scripts\00-packages.sh...
[HOST: 10.40.240.189] ⏳ Uploading scripts\00-packages.sh...
[HOST: 10.40.240.189] 🚀 Executing scripts\00-packages.sh...
[HOST: 10.40.240.193] ✅ Successfully executed scripts\00-packages.sh
[HOST: 10.40.240.193] ⏳ Uploading scripts\01-timezone.sh...
[HOST: 10.40.240.193] 🚀 Executing scripts\01-timezone.sh...
[HOST: 10.40.240.189] ✅ Successfully executed scripts\00-packages.sh
[HOST: 10.40.240.189] ⏳ Uploading scripts\01-timezone.sh...
[HOST: 10.40.240.189] 🚀 Executing scripts\01-timezone.sh...
[HOST: 10.40.240.193] ✅ Successfully executed scripts\01-timezone.sh
[HOST: 10.40.240.193] ⏳ Uploading scripts\02-locale.sh...
[HOST: 10.40.240.193] 🚀 Executing scripts\02-locale.sh...
[HOST: 10.40.240.189] ✅ Successfully executed scripts\01-timezone.sh
[HOST: 10.40.240.189] ⏳ Uploading scripts\02-locale.sh...
[HOST: 10.40.240.189] 🚀 Executing scripts\02-locale.sh...
[HOST: 10.40.240.189] ✅ Successfully executed scripts\02-locale.sh
[HOST: 10.40.240.189] 🔄 Disconnecting...
[HOST: 10.40.240.193] ✅ Successfully executed scripts\02-locale.sh
[HOST: 10.40.240.193] 🔄 Disconnecting...

=== Execution Summary ===
HOST            RESULT
10.40.240.189  Success
10.40.240.193  Success
Enter fullscreen mode

Exit fullscreen mode


🌟 Get Started with rconf Today!

If you’re looking for a straightforward, efficient way to manage remote script execution, rconf is the tool for you. It’s lightweight, secure, and easy to integrate into existing workflows.

🔗 Check out the rconf GitHub repository for more details!

Happy automating! 🚀

Check out our other content

Check out other tags:

Most Popular Articles