如果测试文件/目录是否存在通过SSH /须藤在Python /猛砸 [英] Test if File/Dir exists over SSH/Sudo in Python/Bash
问题描述
我是在远程服务器上安装证书,并要检查它们是否存在之前,我覆盖它们。该服务器只允许通过ssh公钥非root权限。我能须藤-S
来在shell根一次。根是必需的,因为在/ etc / SSL不是被其他人可读。这是在蟒蛇面料
正在开发中,这样就可以在shell命令通过须藤
运行的任何命令会工作。我不介意在这种情况下,键入在提示密码。
TL; DR:我需要一个 SH
命令,可以告诉我的Python程序时是否作为运行一个远程文件(或目录)存在如果fabric.sudo(sh_command)==真:
(或类似的东西)
感谢您!
从fabric.contrib.files进口存在高清富():
如果存在('/路径/要/远程/文件',use_sudo = TRUE):
#命令
I am installing certificates on a remote server and want to check whether they exist before I overwrite them. The server only allows non-root access via ssh public key. I can sudo -s
to root once in a shell. Root is required because /etc/ssl is not readable by anyone else. This is being developed in python fabric
, so any command that can be run in a shell command via sudo
would work. I don't mind typing in passwords at prompts in this case.
TL;DR: I need an sh
command that can tell my python program whether a remote file (or directory) exists when run as if fabric.sudo(sh_command) == True:
(or something similar).
Thank you!
from fabric.contrib.files import exists
def foo():
if exists('/path/to/remote/file', use_sudo=True):
#command
这篇关于如果测试文件/目录是否存在通过SSH /须藤在Python /猛砸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!