Package: plinux
PlinuxCross-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.InstallationFor most users, the recommended method to install is via pip:pip install plinuxImportfromplinuximportPlinuxUsageThe most recommended usage way:fromplinuximportPlinuxclient=Plinux(host="172.16.0.124",username="bobby",password="qawsedrf")response=client.run_cmd("hostname")print(response.stdout)# WebServerprint(response.ok)# TruefromplinuximportPlinuxclient=Plinux()response=client.run_cmd_local("hostname")print(response.stdout)# WebServerprint(response.ok)# TrueCommand using sudo:fromplinuximportPlinuxclient=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)# SSHResponse(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)# 0SFTP usage:fromplinuximportPlinuxtool=Plinux(host="ftp.test.local",username="bobby",password="qawsedrf")sftp=tool.sftpprint(sftp.listdir())SQLite3 usage:fromplinuximportPlinuxclient=Plinux(host="cdn1.test.local",username="bobby",password="qawsedrf")db_path='/opt/ProductName/rxdb/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}AliasesSome methods have "human commands" and aliases:client.run_cmd("cat /home/bobby/text")client.cat("/home/bobby/text")Changelog.. contents::UNRELEASED2.1.3debug log updatedpackage build config updated2.1.2cat_ini returns raw config2.1.1cat_ini: "raw" param added2.1.0 (5.09.2023)stdout and stderr will not be stripped2.0.9 (24.3.2023)run_cmd changes: timeout param renamed to the exec_timeout and fixedclient creation params added to debug log2.0.8.post1 (5.3.2023)from now on, stdout will not return configcat_ini method added instead2.0.8.post0 (1.3.2023)reading empty .ini fixed2.0.8 (28.2.2023).cat can read configs (.ini like)SSHResponse debug loger added2.0.7a1 (26.12.2022)Breaking changes. High level methods removingcatpslscpdateosnetstatstartstopstatusrestartversionrmchpasswdcountstatmd5ufwget_package_infoget_ssl_serialget_ssl_fingerprintget_ssl_certificateget_ssl_md5validate_ssl_keykill_user_sessionget_user_idget_process_cmdlineget_port_listeners_process_idget_dir_sizeget_disk_sizeget_free_spaceget_disk_usagechange_passwordcount_fileslist_dircreate_directoryshutdownrebootget_processesget_md5copy_fileextract_filesremovecompare_filesget_last_filedelete_line_from_filechange_line_in_fileclear_filecreate_fileget_preloginget_netstat_infoget_pidis_service_enableddisableenablelist_active_servicesget_service_journalrestart_servicestart_servicekill_servicestop_serviceis_service_activeget_serviceget_time_dateget_dateget_package_infois_security_update_availableis_package_upgradableget_installed_packages_versionsget_package_versionget_ufw_statusget_hostnameget_ipget_os_versiongrep_line_in_file renamed to the "grep"cat_file renamed to the "cat"2.0.6 (17.11.2022)Methods will not raise exception from nowrebootshutdownis_service_activeis_enabled renamed to is_service_enabled alsoget_service_status removed. Use is_service_active instead2.0.5 (26.10.2022)Fixed methods:grep_line_in_fileis_security_update_available2.0.4 (26.10.2022)exists() fixed2.0.3 (06.10.2022)New method added:compare_files()run_cmd() extended with the "ignore_errors=False" param
Added all other exceptions handler during connection
RemoteCommandExecutionError will rise directly2.0.2 (06.10.2022)get_json() removedcat_file() extended with pprint paramget_dir_size() fixed2.0.1 (06.10.2022)stdout type hint extendedget_ntp_servers() fixed to process different ways of data storing in /etc/systemd/timesyncd.conf2.0.0 (05.10.2022)Breaking changes:response with expected exit code != 0 will be warned in logResponseParser changed and renamed to the SSHResponselog level addedlog format changed to match another appscheck_exists renamed to the .exists()get_prelogin() new method added to read MOTDstat_file() extended. "executable" and time of last access/birth/modification/satusget_directory_size refactored and renamed to get_dir_size()get_current_os_name() deprecatedChanged type of returned value:
str:get_service,get_service_status,get_service_journal,get_ssl_md5,get_ssl_certificate,bool:stop_service/kill_service/start_service/restart_service,enable/disable,get_netstat_info,create_file,clear_file,remove,extract_files,copy_file,reboot,shutdown,create_directory,kill_user_session,list:get_ntp_servers1.3.8 (22.06.2022)get_ufw_status() new method addedchange_hostname() obsoleteget_file_permissions() changes: renamed to stat_file() and return dict nowget_file_size() deprecated. use .stat_file()__sudo_cmd removed1.3.7 (21.06.2022)get_package_info(): new method addedget_md5() returns md5 text onlylist_dir() returns list of files nowget_free_space() returns string with free spaceget_disk_usage() returns dict with disk usageget_last_file() returns str with last file in directorycat_file() returns str with file contentget_package_version() returns str with package versionget_hostname() returns str with hostnameget_os_version() returns dict with OS infoget_ip() returns str with IP address1.3.6 (07.06.2022)get_ip_addresses_show() fixed to return info for specific interface1.3.5 (06.06.2022)python-dateutil added as dependency.New features:get_ntp_servers()get_time_date()to_known_type() auxiliary method to convert string to python known data type1.3.4 (03.06.2022)get_ip_addresses_show() new method added1.3.3 (17.04.2022)refactored to manage logger state1.3.2 (4.04.2022)exceptions moved to separate "exceptions" module. e.g... code-block:: pythonfrom plinux.exceptions import PackageNotFoundError

raise PackageNotFoundError1.3.1 (4.04.2022)logger replaced with the plogger package1.3.0.post1 (22.03.2022)code cleanup1.2.9 (22.03.2022)New method added:.get_user_id()1.2.8 (28.02.2022).sqlite3() extended with the timeout=1000 param1.2.7 (22.02.2022)PackageNotFoundError added1.2.6 (18.02.2022)New methods added:.is_security_update_available().get_disk_size().get_directory_size().get_port_listeners_process_id().get_process_cmdline()1.2.5 (07.02.2022).get_json() extended to decode BOM1.2.4 (21.01.2022)Created instance with local execution by default (host=127.0.0.1).
Python minimum version now is 3.9
New method added:get_installed_packages_versions: Get all installed packages and their versions. Returns dict.
Minor: added some methods description1.2.3 (7.12.2021)New method added:get_ssl_fingerprintget_ssl_serialget_pid fixed to process list of pids1.2.2 (7.12.2021)get_free_space fixedNow it executes command towards "/" and with -h param by default.method can accept different number of positional parameters as additional command argument ()Specify empty mount_point (the first param as '') to get all disk info1.2.1 (22.11.2021)Added:get_package_versionis_package_upgradableclear_fileget_ssl_certificatevalidate_ssl_keyget_ssl_md51.2.0 (14.10.2021)logger added as attr for inheritance1.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" param1.1.8 (13.02.2021)run_cmd_session method added. Can execute several commands one-by-oneResponseParser 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 host1.1.6 (29.11.2020)sqlite3 method updated to accept external parameters like "-line -header"1.1.5 (07.11.2020)sqlite3 method added1.1.4 (06.11.2020)added 'sftp' property explicitly'cat', 'check_exists', 'get_json' now support sudo usage1.1.3 (08.08.2020)get_pid method added1.1.2 (25.04.2020)send_cmd deprecatedfix password prompt in stderr1.1.1 (29.03.2020)get_md5 method added1.1.0 (19.03.2020)ResponseParser extended with json()1.0.9 (28.02.2020)Log filehandler writes in utf8 from now1.0.8 (06.02.2020)get_file_permission extended:added faqadded "human=False" param returns access rights in human readable form otherwise in in octaladded alias "stat"1.0.7 (30.01.2020)ResponseParser methods notation changed.stdout -> strstderr -> strexited -> intok -> boolcommand -> str1.0.6 (29.01.2020)kill_user_session method added1.0.5 (26.01.2020)logging refactored to avoid multiple log entries