How can I remotely execute a script in Windows?

前端 未结 5 955
旧时难觅i
旧时难觅i 2020-12-16 01:58

I would like to have a Windows 2003 server fire a script to fire another script in a separate Windows Server 2008 computer.

I have been told that Powershell can do t

5条回答
  •  悲&欢浪女
    2020-12-16 02:47

    Speaking about PsExec, I would strongly suggest to use Cygwin/OpenSSH instead.

    SSH has multiple advantages (over tools like PsExec or even custom-made services).
    For example, try to use with PsExec and implement what these bash / ssh command lines do:

    ssh user@remotehost "find . -name something" 2> all.errors.txt
    ssh user@remotehost "grep -r something ."
    if [ "$?" == "0" ]
    then
        echo "FOUND"
    else
        echo "NOT FOUND"
    fi
    

    Good Luck!

    • SSH transfers (!) remote stdout / stderr / exit status to local shell for inspection
      (killer feature and common requirement to integrate remote execution into logic of local scripts)

    • Cygwin/OpenSSH provides standard POSIX shell environment
      (efficient time investment, fundamental tools, cross-platform ready, compatible habits, etc.)

    • You can still/always run all native Windows application
      (including automatic execution of *.bat files by cmd processor)

    • You can configure password-less auth using public keys
      (think about unattended automated tasks)


    Tip

    There was one requirement I had problems with initially:
    background sshd service had to execute apps in user's graphical session
    (to make application window appear in desktop environment).

    The acceptable solution for me was running sshd service directly in user's GUI session
    (start automatically when user logs in, follow the link to see configuration file changes):

    /usr/sbin/sshd -f /home/user/sshd_config
    

提交回复
热议问题