Home > python > Remote control a script from home via dropbox

Remote control a script from home via dropbox

Problem
At my workplace I want to leave a script running on my desktop 24h/day. However, from home I cannot login to my machine, so if I want to stop/pause the script, I must go in to the office.

Still, how could I give commands for such a script from home?

Solution
I came up with the following idea. The script is put in my Dropbox folder and it is launched from there. At home I can create some special command files that are automatically synchronized on my office machine too. And when the script notices such a command file, it can react. My command files are called “stop” and “wait” and they can be empty.

The script checks periodically the presence of these files:

def check_commands():
    """
    Remote commands via dropbox.
    """   
    if os.path.isfile('stop'):
        os.unlink('stop')
        print '\nstop received, terminated.'
        sys.exit()
    #
    while os.path.isfile('wait'):
        sys.stdout.write('w')
        time.sleep(5)

The command “stop” terminates the script. The command “wait” pauses the program.

Advertisements
Categories: python Tags: ,
  1. November 15, 2012 at 05:05

    How to use / start the script?!

    • November 15, 2012 at 05:58

      I do that manually. But then I can control it from a remote location.

  2. November 17, 2012 at 16:17

    You can always use the old school method:
    screen and ssh =)

  3. March 10, 2013 at 18:20

    I find this really cool :) thanks

  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: