Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test if File/Dir exists over SSH/Sudo in Python/Bash [duplicate]

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!

like image 235
mh00h Avatar asked Jul 29 '13 04:07

mh00h


1 Answers

from fabric.contrib.files import exists

def foo():
    if exists('/path/to/remote/file', use_sudo=True):
        #command
like image 74
Yuichiro Avatar answered Oct 07 '22 13:10

Yuichiro