This Python script empowers you to offload computationally intensive tasks to a Raspberry Pi or other IoT devices connected to your network, all via SSH. By utilizing this script, you can automate remote task execution and reduce the burden on your primary system.
Before deploying this script, ensure the following prerequisites are met:
- Python 3.x
- paramiko library (install with
pip install paramiko
) - dotenv library (install with
pip install python-dotenv
) - SSH access to the target Raspberry Pi or IoT device with appropriate permissions
-
Clone this repository and navigate to the project directory.
-
Create a virtual environment (venv) to isolate project dependencies:
python3 -m venv venv
-
Activate the virtual environment:
-
On macOS and Linux:
source venv/bin/activate
-
On Windows:
.\venv\Scripts\Activate.ps1
OR
.\venv\Scripts\activate.bat
-
-
Create a
.env
file within the project directory with the following structure:server=your_server_hostname port=your_ssh_port user=your_ssh_username password=your_ssh_password ssh_public_key=your_public_key_path # (Only if using public key authentication; use forward slashes for paths on Windows)
Replace
your_server_hostname
,your_ssh_port
,your_ssh_username
,your_ssh_password
, andyour_public_key_path
with the actual server details and authentication methods for your Raspberry Pi or IoT device. On Windows, use forward slashes (/
) in thessh_public_key
path. -
Install the required packages from
requirements.txt
:pip install -r requirements.txt
Execute the script from the command line, specifying the desired command and its arguments:
python3 run.py -b <base command> -a <arguments> [-s] [-n] [-p]
-b <base command>
: The core command you wish to execute remotely (e.g.,python
,ffmpeg
,curl
).-a <arguments>
: Additional arguments or options to accompany the base command.
Optional Flags:
-s
or--save-output-remote
: Save the command output to a file on the remote device.-n
or--no-output-local
: Do not display the output in the terminal (useful for background tasks).-p
or--use-public-key-remote
: Use public key authentication for the SSH connection (requires specifyingssh_public_key
in the.env
file).
For example:
python3 run.py -b python -a my_script.py
This will run the my_script.py
Python script on the Raspberry Pi or IoT device and display the output.
-
SSH Connectivity: The script securely establishes an SSH connection with the remote Raspberry Pi or IoT device.
-
Command Verification: It checks if the specified base command is available on the target device before execution.
-
Remote Execution: Offload compute-intensive tasks to the remote device, freeing up resources on your primary system.
-
Ensure that you possess valid SSH access rights and permissions for command execution on the Raspberry Pi or IoT device.
-
Exercise caution when utilizing this script, especially with potentially resource-intensive tasks, to avoid overloading the remote device.
Feel encouraged to contribute to this project or report any encountered issues.