Is it possible to run a command on windows server from Linux?
Solution 1
Check out winexe - it depends on samba, uses RPC to run remote commands and might even come with your distribution's packages.
Edit: even if your distro does not have it precompiled and you do not want to compile yourself, you should check out the Build Service - it is likely to have the binary version you would need for your system.
Solution 2
As others have suggested elsewhere, you can setup an ssh server on the win box with cygwin and run .bat or .cmd files remotely that way.
Solution 3
You haven't really described what you want done or how often you want it done.
If what you want done is repetitive and parameterizable you can use the age old solution of creating a daemon on the remote server that periodically checks for file entries in a shared directory, where the file entries contain the parameters for the script. That's how print servers and many other daemons first worked. If you do it that way then regular old windows scheduled tasks, batch files, and shared directories will take you far.
The modern version (and perhaps much more overkill) of that of course is to create a simple webserver on the windows machine that performs your db restore task whenever someone requests the appropriate url.
Solution 4
You can start the Telnet service on the Windows server and then run the command through a Telnet session.
Related videos on Youtube
BioLounge
Updated on September 18, 2022Comments
-
BioLounge over 1 year
I want to restore a sqlserver db backup on remote windows server from linux. I tired "net rpc" but there is nothing for execute a command or script on remote server.
-
FooBee over 12 yearsThe dependency appears to be Samba4, not Samba(3).
-
the-wabbit over 12 yearsPossible. We use a statically compiled version for several years now without running Samba4 - it works.
-
Massimo over 12 yearsOf course. But both the server and the client are built-in in Windows and Linux, so this is by far the easiest solution.
-
FooBee over 12 yearsI agree, but I felt the warning is necessary nevertheless (and the downvote isn't mine :) ).
-
the-wabbit over 12 yearsCan't you see the downvoter's identities above 20k of reputation and start a crusade of wrath and revenge? If not, it surely is worth a feature request.
-
Massimo over 12 yearsNo, voters' identities are never shown.
-
BioLounge over 12 yearsecho SqlCmd -E -S MyServer –Q “RESTORE DATABASE [MyDB] FROM DISK=’D:sqlserverDB.bak’” | net rpc shell -I IPADDRESS -U USERNAME%PASSWORD Do you think this way I can execute the restore command on the remote windows server with net rpc?
-
the-wabbit over 12 yearsNo. The "net rpc shell" command is simply an "interactive shell for remote server/account management". It won't allow you running arbitrary commands.
-
the-wabbit over 12 years@Massimo - simply claiming otherwise would prevent unnecessary downvotes with the least harm done.
-
Massimo over 8 yearsAgain with the downvotes. What's with (some of) you, guys?!? :/