You are not logged in.

#1 2010-02-07 14:37:08

rune0077
Member
Registered: 2009-04-11
Posts: 135

Python: check if file exists on server

Okay here's the scenario: two servers, A and B. I need to run a python-script from server A that checks if a specific file exists on a path on server B. I can easily enough do this locally, but how do I do it across two servers that are not physically connected?

If it helps, both servers are set up with ssh-keys.

Any help greatly appreciated.

Offline

#2 2010-02-07 14:44:38

Ashren
Member
From: Denmark
Registered: 2007-06-13
Posts: 1,229
Website

Re: Python: check if file exists on server

You can run commands with ssh e.g.:

ssh user@server 'file-checking script'

Offline

#3 2010-02-07 14:48:00

rune0077
Member
Registered: 2009-04-11
Posts: 135

Re: Python: check if file exists on server

Ashren wrote:

You can run commands with ssh e.g.:

ssh user@server 'file-checking script'

Ah, but then the script needs to be located on the remote server, right?

Offline

#4 2010-02-07 14:57:38

Ashren
Member
From: Denmark
Registered: 2007-06-13
Posts: 1,229
Website

Re: Python: check if file exists on server

Well, you can easily check for a file using bash and standard GNU tools, which should exist on the remote server if it is running *nix.

Offline

#5 2010-02-07 22:25:38

sabooky
Member
Registered: 2006-11-02
Posts: 89

Re: Python: check if file exists on server

 ssh user@server '[[ -f /path/to/file ]]'

Check the exit status.

type 'help test' in bash to see all options.

Offline

Board footer

Powered by FluxBB