The cross-platform tool to execute bash commands remotely.
Project description
Plinux
Cross-platform tool to work with remote Linux OS.
Plinux based on paramiko project. It can establish ssh connection to a remote server, execute command as user or with sudo rights. Plinux returns object with exit code, sent command, stdout/sdtderr response.
Installation
For most users, the recommended method to install is via pip:
pip install plinux
Import
from plinux import Plinux
Usage
Command from usual user:
from plinux import Plinux
client = Plinux(host="172.16.0.124", username="bobby", password="qawsedrf")
response = client.run_cmd("hostname")
print(response.stdout) # WebServer
print(response.ok) # True
Command using sudo:
from plinux import Plinux
client = Plinux(host="172.16.0.124", username="bobby", password="qawsedrf", logger_enabled=True)
response = client.run_cmd("systemctl stop myservicename.service", sudo=True)
print(response) # ResponseParser(response=(0, None, None, "sudo -S -p '' -- sh -c 'systemctl stop myservicename.service'"))
print(response.command) # sudo -S -p '' -- sh -c 'systemctl stop myservicename.service'
print(response.exited) # 0
SFTP usage:
from plinux import Plinux
tool = Plinux(host="ftp.test.local", username="bobby", password="qawsedrf")
sftp = tool.sftp
print(sftp.listdir())
SQLite3 usage:
from plinux import Plinux
client = Plinux(host="cdn1.test.local", username="bobby", password="qawsedrf")
db_path = '/opt/ProductName/nxdb/StorageConfig.db'
sql = 'select Data from DtoDataContainer'
db = client.sqlite3(db_path, sql).json()
print(db) # {"Settings1": 1, "Settings2": 2...,"Settings10": 10}
print(db['Setting1']) # {"Settings1": 1}
Aliases
Some methods have "human commands" and aliases:
- client.run_cmd("ls /home/bobby")
- client.list_dir("/home/bobby")
- client.ls("/home/bobby")
Changelog
1.2.1 (22.11.2021)
Added:
- get_package_version
- is_package_upgradable
- clear_file
- get_ssl_certificate
- validate_ssl_key
- get_ssl_md5
1.2.0 (14.10.2021)
- logger added as attr for inheritance
1.1.9 (12.05.2021)
- create_file, get_file_size, grep_line_in_file, change_line_in_file, delete_line_from_file, get_last_file, remove, extract_files, copy_file, get_md5, create_directory, list_dir to accept "sudo" param
1.1.8 (13.02.2021)
- run_cmd_session method added. Can execute several commands one-by-one
- ResponseParser updated to work with run_cmd_session (NOTE: exit code always be 0 for the "run_cmd_session")
1.1.7 (21.12.2020)
logger extended to catch destination host
1.1.6 (29.11.2020)
sqlite3 method updated to accept external parameters like "-line -header"
1.1.5 (07.11.2020)
sqlite3 method added
1.1.4 (06.11.2020)
- added 'sftp' property explicitly
- 'cat', 'check_exists', 'get_json' now support sudo usage
1.1.3 (08.08.2020)
get_pid method added
1.1.2 (25.04.2020)
- send_cmd deprecated
- fix password prompt in stderr
1.1.1 (29.03.2020)
get_md5 method added
1.1.0 (19.03.2020)
ResponseParser extended with json()
1.0.9 (28.02.2020)
Log filehandler writes in utf8 from now
1.0.8 (06.02.2020)
get_file_permission extended:
- added faq
- added "human=False" param returns access rights in human readable form otherwise in in octal
- added alias "stat"
1.0.7 (30.01.2020)
- ResponseParser methods notation changed.
- stdout -> str
- stderr -> str
- exited -> int
- ok -> bool
- command -> str
1.0.6 (29.01.2020)
- kill_user_session method added
1.0.5 (26.01.2020)
- logging refactored to avoid multiple log entries
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file plinux-1.2.1.post0.tar.gz
.
File metadata
- Download URL: plinux-1.2.1.post0.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0df87edd7dfd5134099b0e73f4365ece12d4f20970345a480764daf06263b19 |
|
MD5 | dc1b45b8d0478d0be7ac21bbca2eff79 |
|
BLAKE2b-256 | 0101c4a19c39a5956a5a27b9d595da471b0c382494ada82e11c0980b246f56a4 |
File details
Details for the file plinux-1.2.1.post0-py3-none-any.whl
.
File metadata
- Download URL: plinux-1.2.1.post0-py3-none-any.whl
- Upload date:
- Size: 21.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 458c7ad4c59e813c59e4707c3684a171c0f51b9dc7d3b6071218b1cb3960eaa7 |
|
MD5 | b3a417cd2fe7043080140a55e610372d |
|
BLAKE2b-256 | 44310e9f7f15af4c304f459484d941080ead8021e23eeee44a8a4c447002e68d |