Python + bash
Если вам часто требуется запускать shell команды из Python-кода, какой способ вы используете?
Самый низкоуровневый это функция os.system(), либо os.popen(). Рекомендованный способ это subprocess.call(). Но это всё еще достаточно неудобно.
Советую обратить своё внимание на очень крутую библиотеку sh.
Что она умеет?
🔸 удобный синтаксис вызова команд как функций
# os
import os
os.system("tar cvf demo.tar ~/")
# subprocess
import subprocess
subprocess.call(['tar', 'cvf', 'demo.tar', '~/'])
# sh
import sh
sh.tar('cvf', 'demo.tar', "~/")
🔸 простое создание функции-алиаса для длинной команды
fn = sh.lsof.bake('-i', '-P', '-n')
output = sh.grep(fn(), 'LISTEN')
в этом примере также задействован пайпинг
🔸 удобный вызов команд от sudo
with sh.contrib.sudo:
print(ls("/root"))
Такой запрос спросит пароль. Чтобы это работало нужно соответствующим способом настроить юзера.
А вот вариант с вводом пароля через код.
password = "secret"
sudo = sh.sudo.bake("-S", _in=password+"\n")
print(sudo.ls("/root"))
Это не все фишки. Больше интересных примеров смотрите в документации.
Специально для Windows💀 юзеров
#libs#linux
Lassa fever (LF) initially presents like other common illnesses accompanied by a fever, such as malaria.
Healthcare workers are urged to remain vigilant.
Consider a #LF diagnosis when seeing patients showing symptoms of fever.
🔗Health Advisory
https://www.ncdc.gov.ng/news/507/lassa-fever-public-health-advisory
📜
Annual outbreaks of #LassaFever involve the infection and death of a loved family member, a spouse, a parent, and often seasoned healthcare workers and team members.
Our #LF health advisory provides measures through which health workers and the public can protect themselves.
🔗Read via https://www.ncdc.gov.ng/news/507/lassa-fever-public-health-advisory
📣JOIN IN
Our #LassaFever Research Colloquium is LIVE!
The colloquium aims to review the current situation and identify research priorities that will bring about a better understanding of #LF transmission using a One Health approach
🗓️TODAY, May 2nd, 2023
🕗 9:00 a.m. WAT
Register to join:
https://us06web.zoom.us/webinar/register/WN_N0qf8u_IR0W_8k1UaiCnaA
Healthcare workers should raise suspicion for patients with a history of contact with
➡️a probable/confirmed case of #LassaFever within 21 days of onset of fever
➡️body fluids/tissues of a patient with a febrile illness, symptoms & signs suggestive of #LF
🔗Read and share
https://www.ncdc.gov.ng/themes/common/docs/protocols/92_1547068532.pdf
Healthcare workers are advised to always be vigilant - lookout for symptoms of #LassaFever, not all fevers are malaria.
Any febrile illness that has not responded to the use of anti-malaria or antibiotics after 48 hrs should raise an index of suspicion for #LF.
#LassaFeverInfo