fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fab-user] How do I search for files remotely using glob.glob?


From: Jeff Forcier
Subject: Re: [Fab-user] How do I search for files remotely using glob.glob?
Date: Fri, 24 Sep 2010 19:48:02 -0400

Hi,

Fabric is for running shell commands on the remote machine -- not
Python code. If you need to run actual, bona fide Python remotely, you
may want to look at the execnet or pyro projects. Otherwise, if you
are relatively handy with Unix, you can always make stuff work with
Fabric.

For example, your below attempt at using Python's glob.glob might be
rewritten as:

    for filename in run('find /var/lib/mysqlbackup -type f -mindepth 1
-maxdepth 1').splitlines():
        # continue as you were...

Or, less verbose but also not as powerful or portable:

    for filename in run('ls -1 /var/lib/mysqlbackup/*').splitlines():
        # etc

Key being to use Python's string parsing to handle the output of
remote shell programs.

HTH,
Jeff

On Fri, Sep 24, 2010 at 6:27 PM, Yungwei Chen <address@hidden> wrote:
> Hi,
>
> I am trying to find a file on the remote machine using glob.glob, but it 
> doesn't do that on the remote machine.
> Do I need to install python 2.6 on the remote machine?
> What am I missing here? Thanks.
>
> Here's the fabfile:
>
> import glob, os, time, sys
> env.hosts = ['address@hidden']
> ....
> def copy_latest_model():
>    last_mod_file = ""
>    for file in glob.glob("/var/lib/mysql-backup/*"):
>        if (file > last_mod_file):
>            last_mod_file = file
>    print last_mod_file,"is the last modified."
>
>
> _______________________________________________
> Fab-user mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/fab-user
>



-- 
Jeff Forcier
Unix sysadmin; Python/Ruby developer
http://bitprophet.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]