Free Downloads, Community Forum,
FAQs and Developer Resources


Make /Tools Your Home | Link to us

Today's posts | Posts since last visit | Most Active Topics

All Forums Register Login Search Subscriptions My Profile Inbox
Tool Warehouse FAQs Resources Help Member List Address Book Logout

Execute a Windows batch file using REXEC

 
Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [SFU / Interix / SUA Technology] >> SFU / Interix - Getting Started >> Execute a Windows batch file using REXEC Page: [1]
Login
Message << Older Topic   Newer Topic >>
Execute a Windows batch file using REXEC - Oct. 8, '04, 2:59:45 PM   
bzink

 

Posts: 4
Joined: Oct. 5, '04,
Status: offline
I am new to SFU. Just installed SFU 3.5 on Win XP Pro.

I need to be able to start a Windows batch file (script) from a remote host using REXEC.

Let's say the Windows batch file is called "C:\rexectest.bat".

What is the appropriate command to run the Windows batch file as a Windows process?

Would the syntax be any different using REXEC from the remote host?

TIA,

Bruce
Post #: 1
RE: Execute a Windows batch file using REXEC - Oct. 10, '04, 4:45:52 AM   
Rodney

 

Posts: 3728
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
Sorry for the delay. The Forum software got updated yesterday & things were delayed.

You will need to know if you are running the Win32 RSHsrv or the Interix (Unix) rsh daemon.

By default the Interix rshd is turned off in the inet.conf file and the Win32 version is
installed to run by default. The configuration (i.e. .rhosts) is different between the two
but the on-line help (from the Start->programs->SFU menu) will guide you.

If you are only going to be doing Win32 things then use RSHsrv (which I'll assume at this
time given your question).
The only issue you'll have is from the side issuing the command if it is a Unix system
that you may need to escape the backslash. Otherwise the command to send is just as you
would issue at a CMD.EXE prompt. If you have issues about things not being found then
you may need to add to your BAT file additional paths for some environment variables.

(in reply to bzink)
Post #: 2
RE: Execute a Windows batch file using REXEC - Oct. 11, '04, 5:24:26 PM   
markfunk

 

Posts: 673
Joined: Mar. 31, '03,
Status: offline
As Rodney says: it's probably better to try to use the Windows rsh server (rshsvc) rather than Interix tools if you're trying to execute Windows utils.

But, if you really need rexec, you can try. Using Interix tools, you need to edit /etc/inetd.conf and make sure the "exec" line is not commented. Then as local Administrator, you need to type:
cd /etc/init.d
sh inet stop
sh inet start

Now the Interix rexec daemon will run. To test it, try:

rexec windowshost -l username -p password "uname -a"

This should display the host information of "windowshost" machine.
To execute your batch script, you'll need to do:

rexec windowshost -l username -p password "runwin32 c:/rexectest.bat < /dev/null > /dev/fs/C/rexectest.output".

(in reply to Rodney)
Post #: 3
RE: Execute a Windows batch file using REXEC - Oct. 12, '04, 12:54:15 PM   
bzink

 

Posts: 4
Joined: Oct. 5, '04,
Status: offline
I tried both the Windows RSHSRV.EXE and the Interix RSHD and EXEC. I had partial success with both. I cannot use the Win32 RSHsrv because it does not support the "-l" option.

When I use the Interix RSHD and EXEC daemons, and try your test example, everything looks good.

However, when I try to use the "runwin32" command, I get the following:
[Sending Remote Command: "runwin32 c:\rexectest.bat < /dev/null > /dev/fs/C/rexectest.output"]
doscmd: /bin/runwin32[109]: /dev/fs/C/Windows/system32/cmd.exe: No such device
[Remote Command Completed]

I'm guessing this has to do with some permissions that aren't right somewhere, but can't find a message in the Windows event logs or the SYSLOGD messages that helps narrow it down.

The "runwin32 C:\rexectest.bat" runs correctly from a local KSH prompt.

TIA,

Bruce

(in reply to markfunk)
Post #: 4
RE: Execute a Windows batch file using REXEC - Oct. 12, '04, 1:08:23 PM   
Rodney

 

Posts: 3728
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
By default syslogd isn't running. The man page has special information
about getting it started. Not saying this will give additional info in this case,
but just so you know.

> doscmd: /bin/runwin32[109]: /dev/fs/C/Windows/system32/cmd.exe: No such device

The message from CMD.EXE won't be in syslog and unlikely in the Win32 event log either.
What the message means is that either or both of the input and output handles are seen
as being attached to a socket. Win32 is not as flexible as Unix for what it's I/O is
attached to. The redirections for I/O that you had will work on the raw Win32 command
often. Something is slightly off.

The subtle difference between what Mark gave and you have in your message is the slash.
Mark has a forward slash and you have a backslash. Unix takes the backslash as an escape.
So for a literal backslash you need two of them. Win32 is being flexible with allowing
the forwardslash.

(in reply to bzink)
Post #: 5
RE: Execute a Windows batch file using REXEC - Oct. 12, '04, 1:29:19 PM   
bzink

 

Posts: 4
Joined: Oct. 5, '04,
Status: offline
I've had SYSLOGD running for about a week. Not much useful info there.

Also, I tried several variations of the "slash" in the command line to "runwin32", and all came back with the device error (see below).

[Sending Remote Command: "runwin32 c:/rexectest.bat < /dev/null > /dev/fs/C/rexectest.output"]
doscmd: /bin/runwin32[109]: /dev/fs/C/Windows/system32/cmd.exe: No such device
[Remote Command Completed]
[Sending Remote Command: "runwin32 c:\\rexectest.bat < /dev/null > /dev/fs/C/rexectest.output"]
doscmd: /bin/runwin32[109]: /dev/fs/C/Windows/system32/cmd.exe: No such device
[Remote Command Completed]

I also tried the runwin32 command without the redirected input and output, but got the same results (see below):

[Sending Remote Command: "runwin32 c:/rexectest.bat"]
doscmd: /bin/runwin32[109]: /dev/fs/C/Windows/system32/cmd.exe: No such device
[Remote Command Completed]
[Sending Remote Command: "runwin32 c:\\rexectest.bat"]
doscmd: /bin/runwin32[109]: /dev/fs/C/Windows/system32/cmd.exe: No such device
[Remote Command Completed]


What device does it (runwin32?) think is not there?

Is there another way to do this?

TIA,

Bruce

(in reply to Rodney)
Post #: 6
RE: Execute a Windows batch file using REXEC - Oct. 13, '04, 2:03:44 AM   
markfunk

 

Posts: 673
Joined: Mar. 31, '03,
Status: offline
using runwin32 is the best way to go. It simplifies a lot of the windows interactions - like the DOS pathname syntax.

The error message you're getting is because one of the std file descriptors is assigned by Interix to a socket handle which win32 programs cannot cope.

Try "runwin32 .... > /dev/fs/C/junk.out 2>&1"

(in reply to bzink)
Post #: 7
RE: Execute a Windows batch file using REXEC - Oct. 13, '04, 11:54:07 AM   
bzink

 

Posts: 4
Joined: Oct. 5, '04,
Status: offline
I appreciate you sticking with me on this.

I tried your suggestion. I get the same error I received before, but it now is sent to the "junk.out" file (see contents below):

doscmd: /bin/runwin32[109]: /dev/fs/C/Windows/system32/cmd.exe: No such device

I didn't make it clear previously, but the "C:\rexectest.bat" file, specified as "runwin32 C:\\rexectest.bat > /dev/fs/C/junk.out 2>&1", does NOT get executed when I submit the request via REXEC from an authorized remote host. I get the error above (in "junk.out").

However, it does run correctly (and no error messages) on the local machine when invoked from an Interix KSH prompt as "runwin32 C:\\rexectest.bat".

TIA,

Bruce

(in reply to markfunk)
Post #: 8
RE: Execute a Windows batch file using REXEC - Oct. 13, '04, 12:17:56 PM   
Rodney

 

Posts: 3728
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
I've made a test ".BAT" file in /dev/fs/C and the following works for me
when run via rsh:
    rsh machinename "cd /dev/fs/C; runwin32 test.bat < /dev/null > test.out

I'm picking rsh here because it's so similar to rexec, but easier to play
around with the command line. Now in my BAT file I just have "dir /w". I don't know
what's in your BAT file. Perhaps there is something in the BAT file perturbing things too.
Anyway, try the example given here; have to narrow this down in smaller steps I guess.

(in reply to bzink)
Post #: 9
RE: Execute a Windows batch file using REXEC - Oct. 13, '04, 7:25:08 PM   
markfunk

 

Posts: 673
Joined: Mar. 31, '03,
Status: offline
quote:

but the "C:\rexectest.bat" file, specified as "runwin32 C:\\rexectest.bat > /dev/fs/C/junk.out 2>&1", does NOT get executed

This is incorrect. You forgot the " ... < /dev/null ... ".
It is important that you re-direct _all_ the std file descriptors (stdin, stdout and stderr).

(in reply to Rodney)
Post #: 10
Page:   [1]
All Forums >> [SFU / Interix / SUA Technology] >> SFU / Interix - Getting Started >> Execute a Windows batch file using REXEC Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Search All Forums -

Advanced search


SPONSORS



Forum Software © ASPPlayground.NET Advanced Edition 2.5 ANSI

0.047