Re: Python script for remotely shutting down Windows PC from Linux ?



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
.



Relevant Pages

  • Re: head, recursively through file tree?
    ... What's the problem with running a shell or perl inline script ... | child-process to execute the user's commands. ... the shell forks a process for every command it runs unless ...
    (comp.unix.shell)
  • Checking for existence of command prior to execution
    ... alone in an interactive shell it works though. ... it will fail if I add ssh to the list of commands which is ... aliased by the tcsh that is calling the above script. ...
    (comp.os.linux.misc)
  • Re: Maby a litle OT but: apache+sh CGI script
    ... that the http user is added to sudoers and may execute only ... thouse commands that it realy needs for the script. ... it's safer then giving apache full root priv. ...
    (comp.os.linux.security)
  • Re: Maby a litle OT but: apache+sh CGI script
    ... that the http user is added to sudoers and may execute only ... thouse commands that it realy needs for the script. ... it's safer then giving apache full root priv. ...
    (comp.os.linux.security)
  • Re: How to copy scripts to the Terminal
    ... Use 'sh' to execute the commands in the script (if the USB drive is ... > I have been key entering and save it on a removeable device (USB Flash ...
    (alt.linux)