Python script for remotely shutting down Windows PC from Linux ?

Discussion in 'Python' started by diffuser78@gmail.com, May 16, 2006.

  1. Guest

    I am a newbie in Python and want your help in writing python script.

    I have to remotely shut the windows px from linux box. I run OpenSSH on
    windows PC. I remotely connect it from Linux box using
    .....

    ssh Admin@IP_ADDR # connects me fine now without problems
    (LOCAL)

    Next, I wrote a script that would log me in and also shut the windows
    pc down, so I wrote a script

    ssh Admin@IP_ADDR # connects me fine now without problems (LOCAL)
    shutdown -s # This is a windows command (REMOTE)

    Now, when I run this script, it successfully logs me into the windows
    box but doesn't run the second part of the script which is to shut down
    the windows PC. Can you please tell me why ??

    Is there a way using Python script to perform this operation ?

    Every help is appreciated.
    , May 16, 2006
    #1
    1. Advertising

  2. > Next, I wrote a script that would log me in and also shut the windows
    > pc down, so I wrote a script
    >
    > ssh Admin@IP_ADDR # connects me fine now without problems (LOCAL)
    > shutdown -s # This is a windows command (REMOTE)
    >
    > Now, when I run this script, it successfully logs me into the windows
    > box but doesn't run the second part of the script which is to shut down
    > the windows PC. Can you please tell me why ??



    Because you execute both commands locally. ssh opens a connection to the
    remote machine. Then if that connection is terminated, the next command is
    executed. LOCALLY!

    Use

    ssh Admin@IP_ADDR shutdown -s

    to execute commands remote using ssh.

    > Is there a way using Python script to perform this operation ?


    use the subprocess module or shellutils to execute the above.

    Diez
    Diez B. Roggisch, May 16, 2006
    #2
    1. Advertising

  3. Guest

    > ssh Admin@IP_ADDR shutdown -s

    Than indeed worked....Thanks

    > use the subprocess module or shellutils to execute the above.


    I am a python newbie and how easy or difficult it is using the sub
    process module and shell utils.

    Thanks,

    I really appreciate your help.
    , May 16, 2006
    #3
  4. Re: Python script for remotely shutting down Windows PC from Linux?

    wrote:
    >>ssh Admin@IP_ADDR shutdown -s

    >
    >
    > Than indeed worked....Thanks
    >
    > > use the subprocess module or shellutils to execute the above.

    >
    > I am a python newbie and how easy or difficult it is using the sub
    > process module and shell utils.


    It's as difficult as :
    1. read the doc
    2. write some code
    3. test it
    4. if you're in trouble, go back to 1.
    5. if you're still in trouble, post here with relevant infos


    --
    bruno desthuilliers
    python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
    p in ''.split('@')])"
    bruno at modulix, May 16, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Qm9zc29tYQ==?=

    Windows 98 SE freezes when shutting down.

    =?Utf-8?B?Qm9zc29tYQ==?=, Jun 26, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    579
    Eddie
    Jun 27, 2005
  2. Jesper
    Replies:
    10
    Views:
    4,431
    D. Rush
    Sep 29, 2004
  3. Rolf Magnus

    Shutting down Windows 2K +

    Rolf Magnus, Jul 23, 2003, in forum: C++
    Replies:
    9
    Views:
    382
    Scott Condit
    Jul 24, 2003
  4. EW
    Replies:
    6
    Views:
    1,061
  5. Jack
    Replies:
    2
    Views:
    1,583
Loading...

Share This Page